By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

problem storing user input into string

P: n/a
I've learned that some compilers include a string class, and I have
been reading about it. I can use it in the normal way but I have a
question. If I want to have user input stored into my string. I tryed
to use cin.get But for some reason I cannot get the user input into my
string. I first tryed cin.get(name); but I noticed soon that get
method looks for a char* and not a std::string. So I learned that
string has a method that returns a pointer to a const char. How could
I make this work?

string name;
cout << "Name the cat: ";
cin.get((char*)name.c_str(), 10);
cout << "Name is " << name << endl;

output: Name is

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I solved my problem this time. I found yet another refernce to the
sting class and learned of a function getline that solved my problems

string name;
cout << "Name the cat: ";
getline(cin, name);
cout << "Name is " << name << endl;

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.