hey guys i am having a problem here...

i am working on a new text based rpg and im trying to use a name that someone enters

EXAMPLE

#include <iostream>

using namespace std;

int main()
{

         char name;


         cout <<" do you remember you name? " << endl;
         cin >> name;

         cout << name << endl;

         system("pause");
         return 0;

}

and if i enter my name (Ryan) all it returns is r

any ideas

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You have "name" declared as a char, so it can only hold one character. You can change name to a string or a char* and it'll be able to hold more.

example code please lol sry not trying to be any trouble but its a lil hard for me to understand still

To understand more read about 'datatypes' in c++ ..

tyvm both of you :D

Hi.....ı have changed ur code to get result...instead of using char..use string data type for the name variable with getline function.

#include <iostream>
#include <string>

using namespace std;

int main()
{

string name; //string data type for group of the characters...


cout <<" do you remember you name? " << endl;
getline(cin,name); //getline function takes ınput data untıl u press enter button....
//if u use cin>>name instead of getline(cin,name)...ıt wıll take first word of the input data only.

cout << name << endl;

system("pause");
return 0;

}
This article has been dead for over six months. Start a new discussion instead.