Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple file input

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
US
I'm trying to do some text file input but I keep getting an error when I run my program. I set up a very simple program to see if it was something in the rest of my project that was screwing things up, but I get the same error:
The instruction "0x0040f13e" referenced memory at "0xcccccccc". The memory could not be "written".

When I debug it fails inside the iostream class. Here is the code. Very simple and straightforward:

// tmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>


int main(int argc, char* argv[])
{

ifstream in(&quot;D:\\paradoxTest\\txt\\Employee.txt&quot;, ios::in );

if( !in ){
cout<<&quot;something's broken&quot;;
exit( 1 );
}

char *temp;

while(in>>temp){
cout<<temp<<endl;
}


return 0;
}
//**********************************

Now I know it's opening the file because if I change the file name it fails like it should. Has anyone else encountered this error? Is it specific to VC++? Because I've done file input in C++ before without any problems. And this is just a simple console application so I don't think there should be any visual component interfering... Any advice would be great. thanks MYenigmaSELF
myenigmaself@yahoo.com
 
ok, once again I've kind of answered my own question. the char* you pass to the getLine function or overloaded >> operator has to have a constant size(which also has to be big enough to hold the entire line). so:

char *temp;

should be:

char temp[ 100 ];

thanks anyway MYenigmaSELF
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top