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

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
GAWEN STEASY
GAWEN STEASY - avatar