I get an infinite loop from the following code, after entering the string s. Why doesn't it stop at the cin prompt during the next iteration and how can I fix this?
Thanks in advance.
edit: btw, if I enter 3 for 'num' to get out of the loop, it works as expected.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int num;
string s;
do
{
cout << "enter num ";
cin >> num;
cout << "enter s ";
getline(cin, s);
}
while (num != 3);
return 0;
}
Thanks in advance.
edit: btw, if I enter 3 for 'num' to get out of the loop, it works as expected.