I try to read char by char from a file, however, it always give me one or even more new line character("\n") in the end.
The follow is my code:
ifstream file;
file.open(inputfile, ios::binary);
char c;
if(file.is_open()){
while (!file.eof()) {
file.get(c);
if(file.eof()) break;
cout << c << endl;
}
}
file.close();
My file is just one line txt file:
1122aaabbbcccc***
No new line character in the end. However the output of my code is:
1
1
2
2
a
a
a
b
b
b
c
c
c
c
*
*
*
Program ended with exit code: 0
Notice there is two new line character in the end. How can I fix this?