do get() and getline() in c++ treat newline differently? -
ifstream fin; ofstream fout; char ch; string st; fin.open("testfile.txt"); fout.open("testfile.txt"); while(!fin.eof()) { fin.get(ch); cout << ch; } fin.clear(); fin.seekg(ios::beg); while(!fin.eof()) { getline(fin, st); cout << st; }
test file contains following:
abcd efg 1234 hij
result:
abcd efg 1234 hijabcd efg1234 hij
what asking is:
why results different between reading fin.get(ch) , getline(fin, st)?
get()
returns every character. getline()
throws away line terminator.
Comments
Post a Comment