Test file wrote like
Sat Aug 10 22:03:09 2019
Test completed
First i used in.eof(), but someone told me do never use thoes in.eof().
enter code here
#include <fstream>
#include <iostream>
#include <string>
int main() {
//test.txt is a test file.
std::ifstream in("test.txt");
if (!in.is_open()) {
std::cout << "file not found" << std::endl;
return 0;
}
std::string s;
while (in) {
getline(in, s);
std::cout << s << std::endl;
}
return 0;
}
I'd expect the result like
Sat Aug 10 22:03:09 2019
Test completed
But the result is
Sat Aug 10 22:03:09 2019
Test completed
Test completed