this is my code:
Code:
#include<iostream>
#include<fstream>
using namespace std;
void readChar(ifstream &inSFile);
int main() {
ifstream in("in.txt");
readChar(in);
}
void readChar(ifstream &inSFile) {
char ch;
do{
while(inSFile.get(ch)) {
cout << ch;
if(ch=='\n') {
break;
}
}
cout << "got a new line"<<endl;
} while(ch == '\n' && !inSFile.eof());
}
this is my in.txt:
Code:
666666
7777777
88888888
Output:
Code:
666666
got a new line
7777777
got a new line
88888888
got a new line
got a new line
The last line "got a new line" is unexpected, how can I fix it?