I'm having a hard time reading from a .txt file. Here's a short version of what I have:
Code:LoadFile.open("Save File.txt", ios::in); getline(LoadFile, name1); for (int i = 0; i<2;i++) Loadfile >> data[i]; getline(LoadFile, name2); LoadFile.close(); cout << name1 << endl; cout << data[0] << endl; cout << data[1] << endl; cout << name2 << endl;
Here's what the txt. looks like
And here's what gets displayedCode:Bob Smith 50 100 Sam Smith
For some reason, name2 is always empty. Why does getline only work the first time? I tried just doing LoadFile, but then it doesn't grab the Last name because of the space.Code:Bob Smith 50 100



LinkBack URL
About LinkBacks



