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);


and what the different between the 1st cin line and 2nd?
 


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.
 
We can see what you wrote, but you still haven't said what the code is suppose to do, except prompting for a string and number, and outputting "Thank you" whatever you entered.
 

The desired result, current result, and code are all present in my question. Do you need anything else?
 
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