我的程序没有按预期显示输出。
我的文字档案:BNA Boston Red Stockings NA
我的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string team1, team2, team3, id;
string rank;
ifstream inFile;
inFile.open("test.dat");
inFile >> id;
getline(inFile, team1, ' ');
getline(inFile, team2, ' ');
getline(inFile, team3, ' ');
inFile >> rank;
cout << endl << id << endl;
cout << team1 << ' ' << team2 << ' ' << team3 << endl << rank << endl << endl;
system("pause");
return 0;
}
什么是输出(不正确):
BNA
Boston Red
Stockings
我的意思是输出:
BNA
Boston Red Stockings
NA
知道为什么我的程序没有按预期输出? 感谢