(1) |
istream& getline (istream& is, string& str, char delim); |
---|---|
(2) |
istream& getline (istream& is, string& str); |
Get line from stream into string
Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, '\n', for (2)).
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.
return:The same as parameter is.
// extract to string #include <iostream> #include <string> main () { std::string name; std::cout << "Please, enter your full name: "; std::getline (std::cin,name); std::cout << "Hello, " << name << "!\n"; return 0; }
来源:https://www.cnblogs.com/parapax/p/3721205.html