我遇到了一个问题,每当我运行此代码并在studentName输入一个空格时,程序会跳过下一个问题然后结束。
当我有一个学生名字的空格时,这就是它的样子:
http://i.imgur.com/P4WGfcU.png
这就是它应该是这样的:
http://i.imgur.com/1d9oCMy.png
这是我的代码:
string className;
int classTime;
string studentName;
cout<< setw(50);
cout << "Enter the students name: ";
cin >> studentName;
cout << "Enter first class name: ";
cin >> className;
cout << "---------------------------------------------------------------
----------" << endl;
cout << "|" << studentName << "|Monday |Tuesday|Wensday |Thursday|Friday|Saturday|Sunday|" << endl;
cout << "-------------------------------------------------------------------------" << endl;
cout << "| 9:00-10:00 | | | | | | | |" << endl;
cout << "-------------------------------------------------------------------------" << endl;
cout << "| 10:00-11:00| | | | | | | |" << endl;
cout << "-------------------------------------------------------------------------" << endl;
cout << "| 11:00-12:00| | |" << className << "| | | | |" << endl;
答案 0 :(得分:0)
尝试使用std::getline
读取带空格的名称。
cin
会在遇到空格时完成字符串输入。