如果我用Peter Stroll这样的空格键入Name,它就无法工作。在这种情况下如何使用cin.ignore()?
提前谢谢。
int main()
{
ofstream File("player.txt");
cout << "Enter player ID, Name, and Money:" << endl;
cout << "Press Ctrl + Z to quit \n" << endl;
int id;
string name;
int age;
while(cin >> id >> name >> age)
{
File << id << " " << name << " " << age << endl;
}
return 0;
}
答案 0 :(得分:0)
char name [64] = {0}; cin.getline(name,64);