getline () | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

getline ()

i can’t understand what does getline() do? in which situations should i use it and which library does it need?

20th Dec 2017, 9:57 AM
Tornike Vakhtangidze
Tornike Vakhtangidze - avatar
1 Answer
+ 6
// extract to string #include <iostream> #include <string> int main () { std::string name; std::cout << "Please, enter your full name: "; std::getline (std::cin,name); std::cout << "Hello, " << name << "!\n"; return 0; } getline is used to Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, '\n', for  The extraction also stops if the end of file is reached in is or if some other error occurs during the input operation. If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it). Note that any content in str before the call is replaced by the newly extracted sequence. Each extracted character is appended to the string as if its member push_back was called.
20th Dec 2017, 10:03 AM