문제

#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.

도움이 되었습니까?

해결책

Before

getline(cin,name); 

use

cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

To use this statement you need include header <limits>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top