My first attempt with cin and strings

So, I am currently messing around with "cin" and I'd like to be able to take input from users and properly display it back. To me this seemed simple enough but when I attempted this I got some weird errors that don't make any sense. Perhaps one of you guys could look at this and tell me what I did wrong.. I am pretty new at this and programming in general so be gentle with me ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main ()
{
  string mystr;

	  cout << "On a scale of 1 to 10 how cool am i?";
	  getline (cin,mystr);
      stringstream(mystr) >> rating;
	  cout << "You said:" << rating << endl << "I think you are actually a 500 on the coolness scale";
  system("pause");
  return 0;
}
Last edited on
You haven't declared the rating variable. Add int rating;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main ()
{
  string mystr;
  int rating;

	  cout << "On a scale of 1 to 10 how cool am i?";
	  getline (cin,mystr);
      stringstream(mystr) >> rating;
	  cout << "You said:" << rating << endl << "I think you are actually a 500 on the coolness scale";
  system("pause");
  return 0;
}
Last edited on
Oh man.. Such a silly mistake...

Thanks for your help :)
Topic archived. No new replies allowed.