This code is supposed to get one int and one string.But after entering the int, the getline line is acting weird...it dont prompt me for any string input, rather then it shows the same value as the int.
#include<iostream>
#include<string>
using namespace std;
int main()
{
int teacherID;
string teacherName;
cout << "Enter ID: ";
cin >> teacherID;
cout << "Enter Name: ";
getline(cin, teacherName);
cout << teacherID << " " << teacherName << endl;
return 0;
}
After i type 123 for int value following line appers:
Enter ID: 123
Enter Name: 123
Press any key to continue . . .
I think, i need to flush cin.But I dont find any flush method with cin.