Before
getline(cin,name);
use
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
To use this statement you need include header <limits>
Pregunta
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<string>Games;
vector<string>::iterator iter;
string command;
string name;
cin>>command;
if(command=="add"){
cout<<"You have choosen to add a game to your backlog.\n";
cout<<"Enter the name of the Video Game\n";
getline(cin,name);
Games.push_back(name);
cout<<"The Game has been added\n";
}
}
Yes, I know this has been archived. And I know you are supposed to use the getline() function passing into the function the cin and the name of the string to hold the characters, but when I compile and run this after typing the "add" command then the line getline(cin,name) is skipped and I cannot enter anything.
Solución
Before
getline(cin,name);
use
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
To use this statement you need include header <limits>