Files
cppdraft_translate/cppdraft/input/streams.md
2025-10-25 03:02:53 +03:00

61 KiB
Raw Blame History

[input.streams]

31 Input/output library [input.output]

31.7 Formatting and manipulators [iostream.format]

31.7.5 Input streams [input.streams]

31.7.5.1 General [input.streams.general]

1

#

The header defines two class templates and a function template that control input from a stream buffer, along with a function template that extracts from stream rvalues.

31.7.5.2 Class template basic_istream [istream]

31.7.5.2.1 General [istream.general]

1

#

When a function is specified with a type placeholder of extended-floating-point-type, the implementation provides overloads for all cv-unqualified extended floating-point types ([basic.fundamental]) in lieu of extended-floating-point-type.

🔗

namespace std {template<class charT, class traits = char_traits>class basic_istream : virtual public basic_ios<charT, traits> {public:// types (inherited from basic_ios)using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; // [istream.cons], constructor/destructorexplicit basic_istream(basic_streambuf<charT, traits>* sb); virtual ~basic_istream(); // [istream.sentry], prefix/suffixclass sentry; // [istream.formatted], formatted input basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); basic_istream& operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&)); basic_istream& operator>>(ios_base& (*pf)(ios_base&));

basic_istream& operator>>(bool& n); basic_istream& operator>>(short& n); basic_istream& operator>>(unsigned short& n); basic_istream& operator>>(int& n); basic_istream& operator>>(unsigned int& n); basic_istream& operator>>(long& n); basic_istream& operator>>(unsigned long& n); basic_istream& operator>>(long long& n); basic_istream& operator>>(unsigned long long& n); basic_istream& operator>>(float& f); basic_istream& operator>>(double& f); basic_istream& operator>>(long double& f); basic_istream& operator>>(extended-floating-point-type& f);

basic_istream& operator>>(void*& p); basic_istream& operator>>(basic_streambuf<char_type, traits>* sb); // [istream.unformatted], unformatted input streamsize gcount() const; int_type get(); basic_istream& get(char_type& c); basic_istream& get(char_type* s, streamsize n); basic_istream& get(char_type* s, streamsize n, char_type delim); basic_istream& get(basic_streambuf<char_type, traits>& sb); basic_istream& get(basic_streambuf<char_type, traits>& sb, char_type delim);

basic_istream& getline(char_type* s, streamsize n); basic_istream& getline(char_type* s, streamsize n, char_type delim);

basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof()); basic_istream& ignore(streamsize n, char_type delim); int_type peek(); basic_istream& read (char_type* s, streamsize n); streamsize readsome(char_type* s, streamsize n);

basic_istream& putback(char_type c); basic_istream& unget(); int sync();

pos_type tellg(); basic_istream& seekg(pos_type); basic_istream& seekg(off_type, ios_base::seekdir); protected:// [istream.cons], copy/move constructor basic_istream(const basic_istream&) = delete; basic_istream(basic_istream&& rhs); // [istream.assign], assignment and swap basic_istream& operator=(const basic_istream&) = delete; basic_istream& operator=(basic_istream&& rhs); void swap(basic_istream& rhs); }; // [istream.extractors], character extraction templatestemplate<class charT, class traits> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT&); template basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char&); template basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char&); template<class charT, class traits, size_t N> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT(&)[N]); template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char(&)[N]); template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char(&)[N]);}

2

#

The class templatebasic_istream defines a number of member function signatures that assist in reading and interpreting input from sequences controlled by a stream buffer.

3

#

Two groups of member function signatures share common properties: theformatted input functions (orextractors) and theunformatted input functions. Both groups of input functions are described as if they obtain (orextract) inputcharacters by callingrdbuf()->sbumpc() orrdbuf()->sgetc().

They may use other public members ofistream.

31.7.5.2.2 Constructors [istream.cons]

🔗

explicit basic_istream(basic_streambuf<charT, traits>* sb);

1

#

Effects: Initializes the base class subobject withbasic_ios::init(sb) ([basic.ios.cons]).

2

#

Postconditions: gcount() == 0.

🔗

basic_istream(basic_istream&& rhs);

3

#

Effects: Default constructs the base class, copies thegcount() from rhs, callsbasic_ios<charT, traits>::move(rhs) to initialize the base class, and sets the gcount() for rhs to 0.

🔗

virtual ~basic_istream();

4

#

Remarks: Does not perform any operations ofrdbuf().

31.7.5.2.3 Assignment and swap [istream.assign]

🔗

basic_istream& operator=(basic_istream&& rhs);

1

#

Effects: Equivalent to swap(rhs).

2

#

Returns: *this.

🔗

void swap(basic_istream& rhs);

3

#

Effects: Calls basic_ios<charT, traits>::swap(rhs).

Exchanges the values returned by gcount() andrhs.gcount().

31.7.5.2.4 Class basic_istream::sentry [istream.sentry]

🔗

namespace std {template<class charT, class traits>class basic_istream<charT, traits>::sentry {bool ok_; // exposition onlypublic:explicit sentry(basic_istream& is, bool noskipws = false); ~sentry(); explicit operator bool() const { return ok_; } sentry(const sentry&) = delete; sentry& operator=(const sentry&) = delete; };}

1

#

The classsentry defines a class that is responsible for doing exception safe prefix and suffix operations.

🔗

explicit sentry(basic_istream& is, bool noskipws = false);

2

#

Effects: Ifis.good() isfalse, calls is.setstate(failbit).

Otherwise, prepares for formatted or unformatted input.

First, ifis.tie() is not a null pointer, the function callsis.tie()->flush() to synchronize the output sequence with any associated external C stream.

Except that this call can be suppressed if the put area ofis.tie() is empty.

Further an implementation is allowed to defer the call toflush until a call ofis.rdbuf()->underflow() occurs.

If no such call occurs before thesentry object is destroyed, the call toflush may be eliminated entirely.272

If noskipws is zero andis.flags() & ios_base::skipws is nonzero, the function extracts and discards each character as long as the next available input character c is a whitespace character.

Ifis.rdbuf()->sbumpc() oris.rdbuf()->sgetc() returnstraits::eof(), the function callssetstate(failbit | eofbit) (which may throwios_base::failure).

3

#

Remarks: The constructorexplicit sentry(basic_istream& is, bool noskipws = false) uses the currently imbued locale in is, to determine whether the next input character is whitespace or not.

4

#

To decide if the character c is a whitespace character, the constructor performs as if it executes the following code fragment:const ctype& ctype = use_facet<ctype>(is.getloc());if (ctype.is(ctype.space, c) != 0)// c is a whitespace character.

5

#

If, after any preparation is completed,is.good() istrue,ok_ != false otherwise,ok_ == false.

During preparation, the constructor may callsetstate(failbit) (which may throwios_base::failure ([iostate.flags])).273

🔗

~sentry();

6

#

Effects: None.

🔗

explicit operator bool() const;

7

#

Returns: ok_.

272)272)

This will be possible only in functions that are part of the library.

The semantics of the constructor used in user code is as specified.

273)273)

Thesentry constructor and destructor can also perform additionalimplementation-dependent operations.

31.7.5.3 Formatted input functions [istream.formatted]

31.7.5.3.1 Common requirements [istream.formatted.reqmts]

1

#

Each formatted input function begins execution by constructing an object of type ios_base::iostate, termed the local error state, and initializing it to ios_base::goodbit.

It then creates an object of classsentry with thenoskipws (second) argumentfalse.

If thesentry object returnstrue, when converted to a value of typebool, the function endeavors to obtain the requested input.

Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object produces false when converted to a value of type bool, the function returns without attempting to obtain any input.

If rdbuf()->sbumpc() or rdbuf()->sgetc() returns traits::eof(), thenios_base::eofbit is set in the local error state and the input function stops trying to obtain the requested input.

If an exception is thrown during input thenios_base::badbit is set in the local error state,*this's error state is set to the local error state, and the exception is rethrown if (exceptions() & badbit) != 0.

After extraction is done, the input function calls setstate, which sets *this's error state to the local error state, and may throw an exception.

In any case, the formatted input function destroys thesentry object.

If no exception has been thrown, it returns*this.

31.7.5.3.2 Arithmetic extractors [istream.formatted.arithmetic]

🔗

basic_istream& operator>>(unsigned short& val); basic_istream& operator>>(unsigned int& val); basic_istream& operator>>(long& val); basic_istream& operator>>(unsigned long& val); basic_istream& operator>>(long long& val); basic_istream& operator>>(unsigned long long& val); basic_istream& operator>>(float& val); basic_istream& operator>>(double& val); basic_istream& operator>>(long double& val); basic_istream& operator>>(bool& val); basic_istream& operator>>(void*& val);

1

#

As in the case of the inserters, these extractors depend on the locale'snum_get<> object to perform parsing the input stream data.

These extractors behave as formatted input functions (as described in [istream.formatted.reqmts]).

After a sentry object is constructed, the conversion occurs as if performed by the following code fragment, where state represents the input function's local error state:using numget = num_get<charT, istreambuf_iterator<charT, traits>>; use_facet(loc).get(*this, 0, *this, state, val);

In the above fragment,loc stands for the private member of thebasic_ios class.

[Note 1:

The first argument provides an object of theistreambuf_iterator class which is an iterator pointed to an input stream.

It bypasses istreams and uses streambufs directly.

— end note]

Classlocale relies on this type as its interface toistream, so that it does not need to depend directly onistream.

🔗

basic_istream& operator>>(short& val);

2

#

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>;long lval; use_facet(loc).get(*this, 0, *this, state, lval);if (lval < numeric_limits::min()) { state |= ios_base::failbit; val = numeric_limits::min();} else if (numeric_limits::max() < lval) { state |= ios_base::failbit; val = numeric_limits::max();} else val = static_cast(lval);

🔗

basic_istream& operator>>(int& val);

3

#

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>;long lval; use_facet(loc).get(*this, 0, *this, state, lval);if (lval < numeric_limits::min()) { state |= ios_base::failbit; val = numeric_limits::min();} else if (numeric_limits::max() < lval) { state |= ios_base::failbit; val = numeric_limits::max();} else val = static_cast(lval);

🔗

basic_istream& operator>>(extended-floating-point-type& val);

4

#

If the floating-point conversion rank of extended-floating-point-type is not less than or equal to that of long double, then an invocation of the operator function is conditionally supported with implementation-defined semantics.

5

#

Otherwise, let FP be a standard floating-point type:

if the floating-point conversion rank of extended-floating-point-type is less than or equal to that of float, then FP is float,

otherwise, if the floating-point conversion rank of extended-floating-point-type is less than or equal to that of double, then FP is double,

otherwise, FP is long double.

6

#

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>; FP fval; use_facet(loc).get(*this, 0, *this, state, fval);if (fval < -numeric_limits<extended-floating-point-type>::max()) { state |= ios_base::failbit; val = -numeric_limits<extended-floating-point-type>::max();} else if (numeric_limits<extended-floating-point-type>::max() < fval) { state |= ios_base::failbit; val = numeric_limits<extended-floating-point-type>::max();} else { val = static_cast<extended-floating-point-type>(fval);}

[Note 2:

When the extended floating-point type has a floating-point conversion rank that is not equal to the rank of any standard floating-point type, then double rounding during the conversion can result in inaccurate results.

from_chars can be used in situations where maximum accuracy is important.

— end note]

31.7.5.3.3 basic_istream::operator>> [istream.extractors]

🔗

basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));

1

#

Effects: None.

This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts]).

2

#

Returns: pf(*this).

274

🔗

basic_istream& operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));

3

#

Effects: Callspf(*this).

This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts]).

4

#

Returns: *this.

🔗

basic_istream& operator>>(ios_base& (*pf)(ios_base&));

5

#

Effects: Callspf(*this).275

This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts]).

6

#

Returns: *this.

🔗

template<class charT, class traits, size_t N> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& in, charT (&s)[N]); template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char (&s)[N]); template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char (&s)[N]);

7

#

Effects: Behaves like a formatted input member (as described in [istream.formatted.reqmts]) of in.

After asentry object is constructed,operator>> extracts characters and stores them intos.

Ifwidth() is greater than zero, n ismin(size_t(width()), N).

Otherwise n is N.

n is the maximum number of characters stored.

8

#

Characters are extracted and stored until any of the following occurs:

n - 1 characters are stored;

end of file occurs on the input sequence;

letting ct be use_facet<ctype>(in.getloc()),ct.is(ct.space, c) is true.

9

#

operator>> then stores a null byte (charT()) in the next position, which may be the first position if no characters were extracted.

operator>> then callswidth(0).

10

#

If the function extracted no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

11

#

Returns: in.

🔗

template<class charT, class traits> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& in, charT& c); template<class traits> basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char& c); template<class traits> basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char& c);

12

#

Effects: Behaves like a formatted input member (as described in [istream.formatted.reqmts]) of in.

A character is extracted from in, if one is available, and stored in c.

Otherwise,ios_base::failbit is set in the input function's local error state before setstate is called.

13

#

Returns: in.

🔗

basic_istream& operator>>(basic_streambuf<charT, traits>* sb);

14

#

Effects: Behaves as an unformatted input function.

If sb is null, callssetstate(failbit), which may throwios_base::failure ([iostate.flags]).

After a sentry object is constructed, extracts characters from*this and inserts them in the output sequence controlled by sb.

Characters are extracted and inserted until any of the following occurs:

end-of-file occurs on the input sequence;

inserting in the output sequence fails (in which case the character to be inserted is not extracted);

an exception occurs (in which case the exception is caught).

15

#

If the function inserts no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

16

#

Returns: *this.

274)274)

See, for example, the function signaturews(basic_istream&) ([istream.manip]).

275)275)

See, for example, the function signaturedec(ios_base&) ([basefield.manip]).

31.7.5.4 Unformatted input functions [istream.unformatted]

1

#

Each unformatted input function begins execution by constructing an object of type ios_base::iostate, termed the local error state, and initializing it to ios_base::goodbit.

It then creates an object of classsentry with the default argumentnoskipws (second) argumenttrue.

If thesentry object returnstrue, when converted to a value of typebool, the function endeavors to obtain the requested input.

Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object produces false, when converted to a value of typebool, the function returns without attempting to obtain any input.

In either case the number of extracted characters is set to 0; unformatted input functions taking a character array of nonzero size as an argument shall also store a null character (usingcharT()) in the first location of the array.

If rdbuf()->sbumpc() or rdbuf()->sgetc() returns traits::eof(), thenios_base::eofbit is set in the local error state and the input function stops trying to obtain the requested input.

If an exception is thrown during input thenios_base::badbit is set in the local error state,*this's error state is set to the local error state, and the exception is rethrown if (exceptions() & badbit) != 0.

If no exception has been thrown it stores the number of characters extracted in a member object.

After extraction is done, the input function calls setstate, which sets *this's error state to the local error state, and may throw an exception.

In any event thesentry object is destroyed before leaving the unformatted input function.

🔗

streamsize gcount() const;

2

#

Effects: None.

This member function does not behave as an unformatted input function (as described above).

3

#

Returns: The number of characters extracted by the last unformatted input member function called for the object.

If the number cannot be represented, returns numeric_limits::max().

🔗

int_type get();

4

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts a character c, if one is available.

Otherwise,ios_base::failbit is set in the input function's local error state before setstate is called.

5

#

Returns: c if available, otherwisetraits::eof().

🔗

basic_istream& get(char_type& c);

6

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts a character, if one is available, and assigns it to c.276

Otherwise,ios_base::failbit is set in the input function's local error state before setstate is called.

7

#

Returns: *this.

🔗

basic_istream& get(char_type* s, streamsize n, char_type delim);

8

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated bys.277

Characters are extracted and stored until any of the following occurs:

n is less than one or n - 1 characters are stored;

end-of-file occurs on the input sequence;

traits::eq(c, delim) for the next available input character c (in which case c is not extracted).

9

#

If the function stores no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

In any case, if n is greater than zero it then stores a null character into the next successive location of the array.

10

#

Returns: *this.

🔗

basic_istream& get(char_type* s, streamsize n);

11

#

Effects: Callsget(s, n, widen('\n')).

12

#

Returns: Value returned by the call.

🔗

basic_istream& get(basic_streambuf<char_type, traits>& sb, char_type delim);

13

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and inserts them in the output sequence controlled bysb.

Characters are extracted and inserted until any of the following occurs:

end-of-file occurs on the input sequence;

inserting in the output sequence fails (in which case the character to be inserted is not extracted);

traits::eq(c, delim) for the next available input character c (in which case c is not extracted);

an exception occurs (in which case, the exception is caught but not rethrown).

14

#

If the function inserts no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

15

#

Returns: *this.

🔗

basic_istream& get(basic_streambuf<char_type, traits>& sb);

16

#

Effects: Callsget(sb, widen('\n')).

17

#

Returns: Value returned by the call.

🔗

basic_istream& getline(char_type* s, streamsize n, char_type delim);

18

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated bys.278

Characters are extracted and stored until one of the following occurs:

1. end-of-file occurs on the input sequence;
2. traits::eq(c, delim) for the next available input character c (in which case the input character is extracted but not stored);279
3. n is less than one or n - 1 characters are stored (in which case the function calls setstate(failbit)).

19

#

These conditions are tested in the order shown.280

20

#

If the function extracts no characters,ios_base::failbit is set in the input function's local error state before setstate is called.281

21

#

In any case, if n is greater than zero, it then stores a null character (usingcharT()) into the next successive location of the array.

22

#

Returns: *this.

23

#

[Example 1: #include int main() {using namespace std; const int line_buffer_size = 100; char buffer[line_buffer_size]; int line_number = 0; while (cin.getline(buffer, line_buffer_size, '\n') || cin.gcount()) {int count = cin.gcount(); if (cin.eof()) cout << "Partial final line"; // cin.fail() is falseelse if (cin.fail()) { cout << "Partial long line"; cin.clear(cin.rdstate() & ~ios_base::failbit); } else { count--; // Don't include newline in count cout << "Line " << ++line_number; } cout << " (" << count << " chars): " << buffer << endl; }} — end example]

🔗

basic_istream& getline(char_type* s, streamsize n);

24

#

Returns: getline(s, n, widen('\n')).

🔗

basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof());

25

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and discards them.

Characters are extracted until any of the following occurs:

n != numeric_limits::max()numeric.limits andn characters have been extracted so far;

end-of-file occurs on the input sequence (in which case the function callssetstate(eofbit), which may throwios_base::failure ([iostate.flags]));

traits::eq_int_type(traits::to_int_type(c), delim) for the next available input character c (in which case c is extracted).

[Note 1:

The last condition will never occur iftraits::eq_int_type(delim, traits::eof()).

— end note]

26

#

Returns: *this.

🔗

basic_istream& ignore(streamsize n, char_type delim);

27

#

Constraints: is_same_v<char_type, char> is true.

28

#

Effects: Equivalent to: return ignore(n, traits::to_int_type(delim));

🔗

int_type peek();

29

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, reads but does not extract the current input character.

30

#

Returns: traits::eof() ifgood() isfalse.

Otherwise, returnsrdbuf()->sgetc().

🔗

basic_istream& read(char_type* s, streamsize n);

31

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, if!good() callssetstate(failbit) which may throw an exception, and return.

Otherwise extracts characters and stores them into successive locations of an array whose first element is designated bys.282

Characters are extracted and stored until either of the following occurs:

n characters are stored;

end-of-file occurs on the input sequence (in which case the function callssetstate(failbit | eofbit), which may throwios_base::failure ([iostate.flags])).

32

#

Returns: *this.

🔗

streamsize readsome(char_type* s, streamsize n);

33

#

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, if!good() callssetstate(failbit) which may throw an exception, and return.

Otherwise extracts characters and stores them into successive locations of an array whose first element is designated bys.

Ifrdbuf()->in_avail() == -1, callssetstate(eofbit) (which may throwios_base::failure ([iostate.flags])), and extracts no characters;

Ifrdbuf()->in_avail() == 0, extracts no characters

Ifrdbuf()->in_avail() > 0, extractsmin(rdbuf()->in_avail(), n)).

34

#

Returns: The number of characters extracted.

🔗

basic_istream& putback(char_type c);

35

#

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit.

After constructing a sentry object, if!good() callssetstate(failbit) which may throw an exception, and return.

Ifrdbuf() is not null, callsrdbuf()->sputbackc(c).

Ifrdbuf() is null, or ifsputbackc returnstraits::eof(), callssetstate(badbit) (which may throwios_base::failure ([iostate.flags])).

[Note 2:

This function extracts no characters, so the value returned by the next call togcount() is 0.

— end note]

36

#

Returns: *this.

🔗

basic_istream& unget();

37

#

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit.

After constructing a sentry object, if!good() callssetstate(failbit) which may throw an exception, and return.

Ifrdbuf() is not null, callsrdbuf()->sungetc().

Ifrdbuf() is null, or ifsungetc returnstraits::eof(), callssetstate(badbit) (which may throwios_base::failure ([iostate.flags])).

[Note 3:

This function extracts no characters, so the value returned by the next call togcount() is 0.

— end note]

38

#

Returns: *this.

🔗

int sync();

39

#

Effects: Behaves as an unformatted input function (as described above), except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls togcount().

After constructing a sentry object, ifrdbuf() is a null pointer, returns -1.

Otherwise, callsrdbuf()->pubsync() and, if that function returns -1 callssetstate(badbit) (which may throwios_base::failure ([iostate.flags]), and returns-1.

Otherwise, returns zero.

🔗

pos_type tellg();

40

#

Effects: Behaves as an unformatted input function (as described above), except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls togcount().

41

#

Returns: After constructing a sentry object, iffail() != false, returnspos_type(-1) to indicate failure.

Otherwise, returnsrdbuf()->pubseekoff(0, cur, in).

🔗

basic_istream& seekg(pos_type pos);

42

#

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit, it does not count the number of characters extracted, and it does not affect the value returned by subsequent calls togcount().

After constructing a sentry object, iffail() != true, executesrdbuf()->pubseekpos(pos, ios_base::in).

In case of failure, the function callssetstate(failbit) (which may throwios_base::failure).

43

#

Returns: *this.

🔗

basic_istream& seekg(off_type off, ios_base::seekdir dir);

44

#

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit, does not count the number of characters extracted, and does not affect the value returned by subsequent calls to gcount().

After constructing a sentry object, iffail() != true, executesrdbuf()->pubseekoff(off, dir, ios_base::in).

In case of failure, the function calls setstate(failbit) (which may throwios_base::failure).

45

#

Returns: *this.

276)276)

Note that this function is not overloaded on typessigned char andunsigned char.

277)277)

Note that this function is not overloaded on typessigned char andunsigned char.

278)278)

Note that this function is not overloaded on typessigned char andunsigned char.

279)279)

Since the final input character is “extracted”, it is counted in thegcount(), even though it is not stored.

280)280)

This allows an input line which exactly fills the buffer, without settingfailbit.

This is different behavior than the historical AT&T implementation.

281)281)

This implies an empty input line will not causefailbit to be set.

282)282)

Note that this function is not overloaded on typessigned char andunsigned char.

31.7.5.5 Standard basic_istream manipulators [istream.manip]

1

#

Each instantiation of the function template specified in this subclause is a designated addressable function ([namespace.std]).

🔗

template<class charT, class traits> basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);

2

#

Effects: Behaves as an unformatted input function, except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls to is.gcount().

After constructing a sentry object extracts characters as long as the next available character c is whitespace or until there are no more characters in the sequence.

Whitespace characters are distinguished with the same criterion as used bysentry::sentry.

Ifws stops extracting characters because there are no more available it setseofbit, but notfailbit.

3

#

Returns: is.

31.7.5.6 Rvalue stream extraction [istream.rvalue]

🔗

template<class Istream, class T> Istream&& operator>>(Istream&& is, T&& x);

1

#

Constraints: The expression is >> std::forward(x) is well-formed when treated as an unevaluated operand andIstream is publicly and unambiguously derived from ios_base.

2

#

Effects: Equivalent to:is >> std::forward(x);return std::move(is);

31.7.5.7 Class template basic_iostream [iostreamclass]

31.7.5.7.1 General [iostreamclass.general]

🔗

namespace std {template<class charT, class traits = char_traits>class basic_iostream : public basic_istream<charT, traits>, public basic_ostream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; // [iostream.cons], constructorexplicit basic_iostream(basic_streambuf<charT, traits>* sb); // [iostream.dest], destructorvirtual ~basic_iostream(); protected:// [iostream.cons], constructor basic_iostream(const basic_iostream&) = delete; basic_iostream(basic_iostream&& rhs); // [iostream.assign], assignment and swap basic_iostream& operator=(const basic_iostream&) = delete; basic_iostream& operator=(basic_iostream&& rhs); void swap(basic_iostream& rhs); };}

1

#

The class templatebasic_iostream inherits a number of functions that allow reading input and writing output to sequences controlled by a stream buffer.

31.7.5.7.2 Constructors [iostream.cons]

🔗

explicit basic_iostream(basic_streambuf<charT, traits>* sb);

1

#

Effects: Initializes the base class subobjects withbasic_istream<charT, traits>(sb) ([istream]) andbasic_ostream<charT, traits>(sb).

2

#

Postconditions: rdbuf() == sb andgcount() == 0.

🔗

basic_iostream(basic_iostream&& rhs);

3

#

Effects: Move constructs from the rvalue rhs by constructing the basic_istream base class withstd::move(rhs).

31.7.5.7.3 Destructor [iostream.dest]

🔗

virtual ~basic_iostream();

1

#

Remarks: Does not perform any operations onrdbuf().

31.7.5.7.4 Assignment and swap [iostream.assign]

🔗

basic_iostream& operator=(basic_iostream&& rhs);

1

#

Effects: Equivalent to swap(rhs).

🔗

void swap(basic_iostream& rhs);

2

#

Effects: Calls basic_istream<charT, traits>::swap(rhs).