How can you use cin.getline() with std::string data type?

Started by
1 comment, last by dxFoo 18 years, 4 months ago
Hi. As I was reading, I came across this question: how can you use cin.getline() with a std::string data type?

cin >> str;  // this just stores whats before the proceding white space. 

/* 
error: No user-defined-conversion operator available 
that can perform this conversion, or the operator 
cannot be called  
*/

cin.getline(str, sizeof(std::string), '\n'); 


Thanks, dxfoo
Advertisement
You use the free function version:

std::getline(std::cin, my_string);
Great, thanks.

This topic is closed to new replies.

Advertisement