The code must give the output "C++Programming C". But the output i am getting is "C++Programming g". In many cases i have seen when i have forwarded the file pointer , the characters can be well read but when the pointer is brought back the desired characters cannot be read.Code:#include <iostream> #include <fstream> using namespace std; int main() { char c; ofstream fout("O.TXT",ios::out|ios::binary); fout << "C++Programming"; fout.close(); ifstream fin("O.TXT",ios::in|ios::binary); while( !fin.eof() ) { fin.get(c); if( !fin.eof() ) cout << c; } fin.seekg(0,ios::beg); fin.get(c); cout << ' ' << c << endl; fin.close(); system("PAUSE"); return 0; }
Tried on VC++ 6.0 and DEV C++ 4.9.9.0



LinkBack URL
About LinkBacks


