K
Kelly Mandrake
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
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