i am having a problem with my code, because it compiles just fine. the only problem i am having is that when i type in say a full name with space in between the first and last name, it doesn't request for the next variable that it is meant to request for and that just defeats the purpose of the program and how do i store the input into say a file?
#include <iostream>
int main(){
int count = 0;
std::string name;
std::cout << "How many names? ";
std::cin >> count;
std::cin.ignore(); //prepare for following getline()
for( int i = 0; i < count; i++)
{
std::cout << "Please enter name: ";
std::getline(std::cin, name);
std::cout << name << std::endl;
}
return 0;
}
How many names? 3
Please enter name: Bob Smith
Bob Smith
Please enter name: Harry Roberts
Harry Roberts
Please enter name: Ann Mary Sykes
Ann Mary Sykes
Program ended with exit code: 0