I have a console application that shopuld wait for the user to input a string. It has to be getline, because it could contain spaces. But it doesn't wait for input, it skips it and runs the functions anyway. Here's my code:
int main()
{
vector<person> people;
bool flag = true;
int num_people = 0;
//char*filename="names.txt";
people = read_file();
while(flag)
{
int sel = 0;
string args;
cout << "1 - Sök del av personnamn" << "\n"
<< "2 - Sök städer" << "\n" << "3 - Avsluta" << endl;
cin >> sel;
if(sel == 1)
{
cout << "Mata in delen av personnamnet" << endl;
getline(cin, args);
print_result(find_in_names(people, args));
}
else if(sel == 2)
{
cout << "Mata in staden" << endl;
getline(cin, args);
args = lower_letters(args);
print_result(find_person_from_city(people, args));
}
else if(sel==3)
{
flag=false;
}
else
{
cout << "FEL, TRYCK OM!" << endl;
}
}
}
Runs without errors, it just skips the getline and doesn't let the user input anything.