annoying getline

What is the use of getline?


 
 Getline(cin,/*...*/,'/n')

Is it the same as
 
Cin>>/*....*/
Last edited on
1
2
3
4
std::cout << "enter your name: ";
std::string line;
std::cin >> line;
srd::cout << line;
enter your name: Maria Rosa Coccia 
Maria
1
2
3
4
std::cout << "enter your name: ";
std::string line;
std::getline(std::cin, line);
srd::cout << line;
enter your name: Maria Rosa Coccia 
Maria Rosa Coccia 
Thanks MiiNipaa I wondered about this too.
Both getline and (various overloads of) >> do have reference documentation (for example, on this site) that describe their details.
getline() is useful for things like strings, in which you want to get the entire line. Cin>>string will not work, as it will only get the first word. It terminates at whitespaces I believe
Last edited on
ah i see its about whitespace hehe thank you all miniipaa,kitty,keskiverto
Topic archived. No new replies allowed.