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

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++ ..

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;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.