function template
<string>
std::getline (basic_string) (1)template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>& is, basic_string<charT,traits,Alloc>& str, charT delim);(2)
template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>& is, basic_string<charT,traits,Alloc>& str);(1)
template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>& is, basic_string<charT,traits,Alloc>& str, charT delim);template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>&& is, basic_string<charT,traits,Alloc>& str, charT delim);(2)
template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>& is, basic_string<charT,traits,Alloc>& str);template <class charT, class traits, class Alloc> basic_istream<charT,traits>& getline (basic_istream<charT,traits>&& is, basic_string<charT,traits,Alloc>& 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, 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).
Note that any content in str before the call is replaced by the newly extracted sequence.
Each extracted character is appended to the basic_string as if its member push_back was called.
A call to this function may set any of the internal state flags of is if:
flag error eofbit The end of the source of characters is reached during its operations. failbit The input obtained could not be interpreted as a valid textual representation of an object of this type.Additionally, in any of these cases, if the appropriate flag has been set with is's member function basic_ios::exceptions, an exception of type ios_base::failure is thrown.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 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;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4