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
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.Code://.... declarations and stuff pifile.open("teste.txt", ios::in | ios::nocreate); if(!pfile) exit(1); cout << "Displaying the file:" << endl; while(pifile.get(inchar)) cout << inchar; cout << endl << "Returning to the begin:" << endl; pifile.seekg(0L, SEEK_SET); cout << "Reading first line only" << endl; for(int i=1; i<=7; i++) { if(pifile.get(inchar)) cout << inchar; else break; } //....
What am I doing wrong?