Variable trouble

Aug 18, 2011 at 4:11am
Hey i recently wrote a program using variables. The program works fine but when compile nd run the program the variable always comes out as "4370436". Here is the program:

#include <iostream>

int main() {
using namespace std;

int x;


cout << "What is your name";
cin >> x;
cout << "hello " << x;

system("pause");
return 0;
}


when i compile and run it this is the result:

What is your name? Dan
hello 4370436Press any key to continue...

Why is the variable not Dan??! Someone please help!!!
Aug 18, 2011 at 4:18am
hello Dan

Why is the variable not Dan??!

Because you're trying to put text into an int. x should be a std::string instead (found in the <string> header).
Topic archived. No new replies allowed.