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

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -