【发布时间】:2014-01-06 14:45:02
【问题描述】:
下面代码中的getline 函数有问题。在“获取”信息部分,我希望能够存储一个完整的句子,但我不能让它工作。
当我打开我的程序时,它只是跳过信息的输入。
ps:我是 C++ 新手
这是我遇到问题的代码部分(输入信息):
void add() {
string name;
string faction;
string classe;
string race;
string info;
ofstream wowdatabase("wowdatabase.txt", ios::app);
cout << "Add a race or class" << endl;
cout << "---------------------------------------------------------" << endl;
cout << "" << endl;
cout << "Enter the name of the race or class (only small letters!):" << endl;
cin >> name;
cout << "Enter Race (Type -, if writen in name section):" << endl;
cin >> race;
cout << "Enter Class (Type -, if writen in name section):" << endl;
cin >> classe;
cout << "Enter faction (Alliance/Horde):" << endl;
cin >> faction;
cout << "Enter the information:" << endl;
getline(cin, info);
wowdatabase << name << ' ' << faction << ' ' << classe << ' ' << race << ' ' << info << endl;
wowdatabase.close();
system("CLS");
main();
}
现在它工作正常 =) 但是,当我想再次输出信息时,它只显示句子中的第一个单词?
【问题讨论】:
-
这里有一点点:
cout << "" << endl;你不需要"",只需cout << endl;就足够了。 -
在 C++ 中调用
main是非法的。
标签: c++