Cin code failure

Jan 1, 2019
4
0
10
I'll copy and paste my code here, please tell me what I am missing.
/*
Desired result: two successful inputs
current result: one successful input
*/
#include <iostream>

using namespace std;
string problem;
int solutions;
int main()
{
cout << "What is your problem?" << endl << "My problem is that " ;
cin >> problem;

cout << endl << endl << "And how many solutions are there?" << endl;
cin >> solutions;

cout << endl << endl << "thank you";

return 0;
}
 
Solution
From this line of code:

cin >> problem;

Because problem is of type std::string, the extraction operator >> on cin will also terminate on spaces, tabs, newlines, etc. In other words, it will always extract a single word. To get the entire line, you will want to use the following:

getline(cin, problem);
Jan 1, 2019
4
0
10


One is a string variable and the other is an integer variable. Any more questions? The full code is above if you’d like to test it yourself.
 
Jan 1, 2019
4
0
10

The desired result, current result, and code are all present in my question. Do you need anything else?
 

lolnole

Proper
Oct 2, 2018
45
0
110
From this line of code:

cin >> problem;

Because problem is of type std::string, the extraction operator >> on cin will also terminate on spaces, tabs, newlines, etc. In other words, it will always extract a single word. To get the entire line, you will want to use the following:

getline(cin, problem);
 
Solution