CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 14:11:46 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/string/basic_string/getline/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 14:11:46 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"a29f-nLM164mP4ooyTTjAgb4rIWaf+88"
Content-Encoding: gzip
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:
(see ios_base::iostate for more info on these)
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.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
basic_string
- basic_string::~basic_string
- basic_string::basic_string
member functions
- basic_string::append
- basic_string::assign
- basic_string::at
-
basic_string::backC++11
- basic_string::begin
- basic_string::c_str
- basic_string::capacity
-
basic_string::cbeginC++11
-
basic_string::cendC++11
- basic_string::clear
- basic_string::compare
- basic_string::copy
-
basic_string::crbeginC++11
-
basic_string::crendC++11
- basic_string::data
- basic_string::empty
- basic_string::end
- basic_string::erase
- basic_string::find
- basic_string::find_first_not_of
- basic_string::find_first_of
- basic_string::find_last_not_of
- basic_string::find_last_of
-
basic_string::frontC++11
- basic_string::get_allocator
- basic_string::insert
- basic_string::length
- basic_string::max_size
- basic_string::operator[]
- basic_string::operator+=
- basic_string::operator=
-
basic_string::pop_backC++11
- basic_string::push_back
- basic_string::rbegin
- basic_string::rend
- basic_string::replace
- basic_string::reserve
- basic_string::resize
- basic_string::rfind
-
basic_string::shrink_to_fitC++11
- basic_string::size
- basic_string::substr
- basic_string::swap
member constants
non-member overloads
- Reference
- <string>
- basic_string
- getline
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
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.
Parameters
- is
- basic_istream object from which characters are extracted.
- str
- basic_string object where the extracted line is stored.
Return Value
The same as parameter is.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. In this case, distr preserves the parameters and internal data it had before the call. Notice that some eofbit cases will also set failbit. |
badbit | An error other than the above happened. |
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.
Example
|
|
Complexity
Unspecified, but generally linear in the resulting length of str.Iterator validity
Any iterators, pointers and references related to str may be invalidated.Data races
Both objects, is and str, are modified.Exception safety
Basic guarantee: if an exception is thrown, both is and str end up in a valid state.See also
- basic_istream::getline
- Get line (public member function)
- operator>> (basic_string)
- Extract string from stream (function template)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us