У меня есть следующая простая программа, но последняя строка кода getline(cin, topicClass)
никогда не выпрашивается. Однако, если я использую обычный cin>>topicClass
, который выполняется. Не могли бы вы мне помочь? Благодаряgetline (cin, string) не вычитается последней строкой кода
#include <iostream>
#include <string>
using namespace std;
void InfoInput()
{
string classID;
string teacherName;
int totalStudent;
string topicClass;
cout<<"Enter class ID"<<endl;
getline(cin, classID);
cout<<"Enter teacher's name"<<endl;
getline(cin, teacherName);
cout<<"Enter total number of students"<<endl;
cin>>totalStudent;
cout<<"Enter topic of class"<<endl;
getline(cin, topicClass);
//cin>>topicClass;
}
int main()
{
InfoInput();
}
Возможный дубликат http://stackoverflow.com/questions/10553597/cin-and-getline-skipping-input –
Возможно, ничего. Это «прибито!» @ AlgirdasPreidžius – user4581301
Как вы определили, что 'getline' никогда не исполнялся? –