Program skips second cin

前端 未结 4 1533
感动是毒
感动是毒 2021-01-16 12:03

I\'m making a C++ Mind Reader program, which is nearly complete. However, it feels the need to skip the second cin. I\'ve searched and I\'m not exactly sure what\'s wrong. I

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 12:32

    You can only input one word into a cin. Instead, use getline(cin, string name); If it still doesn't work, add a cin.ignore(); before your getline(cin, string name);, like this:

    string country;
    cout << "Now please enter the country you are in at the moment:\n\n";
    cin.ignore();
    getline(cin, country);
    

    This will now definitely work.

提交回复
热议问题