If got a problem for reading multiple data types to a file using operator>> and getline.
Let say I've got the following code:
The problem is that string u is emtpy and not the the content of s that it supposed to have.Code:#include <iostream> #include <string> #include <fstream> using namespace std; int main() { ofstream fout("testfile.txt"); string s = "Writing multiple data types to a file", t, u; fout << s << '\n'; int i = 2, j; fout << i << '\n'; fout << s << '\n'; fout.close(); ifstream fin("testfile.txt"); getline(fin, t); fin >> j; getline(fin, u); cout << t << endl << j << endl << u << endl; return 0; }



LinkBack URL
About LinkBacks


