My file contains "abcdefg". Why when I use this part of code, in console, it prints letter 'g'?
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main () {
char ch;
fstream file;
file.open("myfile.txt", ios::in);
file.setf(ios::skipws);
while (1) {
file >> ch;
if (file.fail()) break;
cout << ch;
cout << "\n";
}
file.close();
return 0;
}
I expect to output all chars except letter 'g'.