C++ C++;空格分隔符问题
我的程序未按预期显示输出 我的文本文件:BNA Boston Red Stockings NA 我的代码:C++ C++;空格分隔符问题,c++,whitespace,delimiter,C++,Whitespace,Delimiter,我的程序未按预期显示输出 我的文本文件: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");
#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
NA
知道我的程序为什么不能按预期输出吗?
谢谢提取后打印每个值。一旦你这样做并弄清楚
team1
是轮子掉下来的地方,考虑一下什么team1
停止消耗字符,以及消耗id
后输入流中的第一个字符是什么(扰流板:它是你传递给getline
)的分隔符。添加一个infle.ignore()
在infle>>id
之后@0x499602D2 infle.ignore()工作正常,谢谢!
BNA
Boston Red Stockings
NA