Trying to do some random file access. But seekg() or get() is not working as I expected... Of course what I was expecting is the problem here :D
The first while block displays the file nicely. But although I get no compile errors, after I seekg it to the beginning, the for loop that follows doesn't display anything. In fact while tracing, not even the break statement is processed. After testing if(pifile.get(inchar)), it immediatly goes to the end bracket.
//.... declarations and stuff
pifile.open("teste.txt", ios::in | ios::nocreate);
cout << "Displaying the file:" << endl;
while(pifile.get(inchar)) cout << inchar;
cout << endl << "Returning to the begin:" << endl;
cout << "Reading first line only" << endl;
for(int i=1; i<=7; i++)
if(pifile.get(inchar)) cout << inchar;
What am I doing wrong?
You need to clear the EOF flag after reading to the end of the file the first time.
I think it's this:
Thanks a bunch Hammer :)
hi, i need, help, i want to now, how i can use the direct files, like fseek, etc, in a program , thanks