675 lines
22 KiB
Markdown
675 lines
22 KiB
Markdown
[istream.unformatted]
|
||
|
||
# 31 Input/output library [[input.output]](./#input.output)
|
||
|
||
## 31.7 Formatting and manipulators [[iostream.format]](iostream.format#istream.unformatted)
|
||
|
||
### 31.7.5 Input streams [[input.streams]](input.streams#istream.unformatted)
|
||
|
||
#### 31.7.5.4 Unformatted input functions [istream.unformatted]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5035)
|
||
|
||
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[.](#1.sentence-1)
|
||
|
||
It then creates an object of classsentry with the default argumentnoskipws (second) argumenttrue[.](#1.sentence-2)
|
||
|
||
If thesentry object returnstrue,
|
||
when converted to a value of typebool,
|
||
the function endeavors
|
||
to obtain the requested input[.](#1.sentence-3)
|
||
|
||
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[.](#1.sentence-4)
|
||
|
||
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[.](#1.sentence-5)
|
||
|
||
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[.](#1.sentence-6)
|
||
|
||
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[.](#1.sentence-7)
|
||
|
||
If no exception has been thrown it
|
||
stores the number of characters extracted
|
||
in a member object[.](#1.sentence-8)
|
||
|
||
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[.](#1.sentence-9)
|
||
|
||
In any event thesentry object
|
||
is destroyed before leaving the unformatted input function[.](#1.sentence-10)
|
||
|
||
[ð](#lib:gcount,basic_istream)
|
||
|
||
`streamsize gcount() const;
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5087)
|
||
|
||
*Effects*: None[.](#2.sentence-1)
|
||
|
||
This member function does not behave as an unformatted
|
||
input function (as described above)[.](#2.sentence-2)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5093)
|
||
|
||
*Returns*: The number of characters
|
||
extracted by the last unformatted input member function called for the object[.](#3.sentence-1)
|
||
|
||
If the number cannot be represented,
|
||
returns numeric_limits<streamsize>::max()[.](#3.sentence-2)
|
||
|
||
[ð](#lib:get,basic_istream)
|
||
|
||
`int_type get();
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5107)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#4.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
a character c, if one is available[.](#4.sentence-2)
|
||
|
||
Otherwise,ios_base::failbit is set in the input function's local error state
|
||
before setstate is called[.](#4.sentence-3)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5117)
|
||
|
||
*Returns*: c if available,
|
||
otherwisetraits::eof()[.](#5.sentence-1)
|
||
|
||
[ð](#lib:get,basic_istream_)
|
||
|
||
`basic_istream& get(char_type& c);
|
||
`
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5130)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#6.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
a character, if one is available, and assigns it to c[.](#6.sentence-2)[276](#footnote-276 "Note that this function is not overloaded on types signed char and unsigned char.")
|
||
|
||
Otherwise,ios_base::failbit is set in the input function's local error state
|
||
before setstate is called[.](#6.sentence-3)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5147)
|
||
|
||
*Returns*: *this[.](#7.sentence-1)
|
||
|
||
[ð](#lib:get,basic_istream__)
|
||
|
||
`basic_istream& get(char_type* s, streamsize n, char_type delim);
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5158)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#8.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
characters and stores them
|
||
into successive locations of an array whose first element is designated bys[.](#8.sentence-2)[277](#footnote-277 "Note that this function is not overloaded on types signed char and unsigned char.")
|
||
|
||
Characters are extracted and stored until any of the following occurs:
|
||
|
||
- [(8.1)](#8.1)
|
||
|
||
n is less than one or n - 1 characters are stored;
|
||
|
||
- [(8.2)](#8.2)
|
||
|
||
end-of-file occurs on the input sequence;
|
||
|
||
- [(8.3)](#8.3)
|
||
|
||
traits::eq(c, delim) for the next available input
|
||
character c (in which case c is not extracted)[.](#8.sentence-3)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5186)
|
||
|
||
If the function stores no characters,ios_base::failbit is set in the input function's local error state
|
||
before setstate is called[.](#9.sentence-1)
|
||
|
||
In any case, if n is greater than zero it then stores a null character
|
||
into the next successive location of the array[.](#9.sentence-2)
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5193)
|
||
|
||
*Returns*: *this[.](#10.sentence-1)
|
||
|
||
[ð](#lib:get,basic_istream___)
|
||
|
||
`basic_istream& get(char_type* s, streamsize n);
|
||
`
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5204)
|
||
|
||
*Effects*: Callsget(s, n, widen('\n'))[.](#11.sentence-1)
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5209)
|
||
|
||
*Returns*: Value returned by the call[.](#12.sentence-1)
|
||
|
||
[ð](#lib:get,basic_istream____)
|
||
|
||
`basic_istream& get(basic_streambuf<char_type, traits>& sb, char_type delim);
|
||
`
|
||
|
||
[13](#13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5220)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#13.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
characters and inserts them
|
||
in the output sequence controlled bysb[.](#13.sentence-2)
|
||
|
||
Characters are extracted and inserted until any of the following occurs:
|
||
|
||
- [(13.1)](#13.1)
|
||
|
||
end-of-file occurs on the input sequence;
|
||
|
||
- [(13.2)](#13.2)
|
||
|
||
inserting in the output sequence fails
|
||
(in which case the character to be inserted is not extracted);
|
||
|
||
- [(13.3)](#13.3)
|
||
|
||
traits::eq(c, delim) for the next available input
|
||
character c (in which case c is not extracted);
|
||
|
||
- [(13.4)](#13.4)
|
||
|
||
an exception occurs
|
||
(in which case, the exception is caught but not rethrown)[.](#13.sentence-3)
|
||
|
||
[14](#14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5244)
|
||
|
||
If the function inserts no characters,ios_base::failbit is set in the input function's local error state
|
||
before setstate is called[.](#14.sentence-1)
|
||
|
||
[15](#15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5249)
|
||
|
||
*Returns*: *this[.](#15.sentence-1)
|
||
|
||
[ð](#lib:get,basic_istream_____)
|
||
|
||
`basic_istream& get(basic_streambuf<char_type, traits>& sb);
|
||
`
|
||
|
||
[16](#16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5260)
|
||
|
||
*Effects*: Callsget(sb, widen('\n'))[.](#16.sentence-1)
|
||
|
||
[17](#17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5265)
|
||
|
||
*Returns*: Value returned by the call[.](#17.sentence-1)
|
||
|
||
[ð](#lib:getline,basic_istream)
|
||
|
||
`basic_istream& getline(char_type* s, streamsize n, char_type delim);
|
||
`
|
||
|
||
[18](#18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5276)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#18.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
characters and stores them
|
||
into successive locations of an array whose first element is designated bys[.](#18.sentence-2)[278](#footnote-278 "Note that this function is not overloaded on types signed char and unsigned char.")
|
||
|
||
Characters are extracted and stored until one of the following occurs:
|
||
|
||
| [1.](#18.1) | end-of-file occurs on the input sequence; |
|
||
| --- | --- |
|
||
| [2.](#18.2) | traits::eq(c, delim) for the next available input character c (in which case the input character is extracted but not stored);[279](#footnote-279 "Since the final input character is âextractedâ, it is counted in the gcount(), even though it is not stored.") |
|
||
| [3.](#18.3) | n is less than one or n - 1 characters are stored (in which case the function calls setstate(failbit))[.](#18.sentence-3) |
|
||
|
||
[19](#19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5313)
|
||
|
||
These conditions are tested in the order shown[.](#19.sentence-1)[280](#footnote-280 "This allows an input line which exactly fills the buffer, without setting failbit. This is different behavior than the historical AT&T implementation.")
|
||
|
||
[20](#20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5322)
|
||
|
||
If the function extracts no characters,ios_base::failbit is set in the input function's local error state
|
||
before setstate is called[.](#20.sentence-1)[281](#footnote-281 "This implies an empty input line will not cause failbit to be set.")
|
||
|
||
[21](#21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5333)
|
||
|
||
In any case, if n is greater than zero, it then stores a null character
|
||
(usingcharT())
|
||
into the next successive location of the array[.](#21.sentence-1)
|
||
|
||
[22](#22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5339)
|
||
|
||
*Returns*: *this[.](#22.sentence-1)
|
||
|
||
[23](#23)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5343)
|
||
|
||
[*Example [1](#example-1)*: #include <iostream>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*]
|
||
|
||
[ð](#lib:getline,basic_istream_)
|
||
|
||
`basic_istream& getline(char_type* s, streamsize n);
|
||
`
|
||
|
||
[24](#24)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5378)
|
||
|
||
*Returns*: getline(s, n, widen('\n'))[.](#24.sentence-1)
|
||
|
||
[ð](#lib:ignore,basic_istream)
|
||
|
||
`basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof());
|
||
`
|
||
|
||
[25](#25)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5389)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#25.sentence-1)
|
||
|
||
After constructing a sentry object, extracts
|
||
characters and discards them[.](#25.sentence-2)
|
||
|
||
Characters are extracted until any of the following occurs:
|
||
|
||
- [(25.1)](#25.1)
|
||
|
||
n != [numeric_limits<streamsize>::max()](numeric.limits.members#lib:numeric_limits,max "17.3.5.2 numeric_limits members [numeric.limits.members]")numeric.limits andn characters have been extracted so far;
|
||
|
||
- [(25.2)](#25.2)
|
||
|
||
end-of-file occurs on the input sequence
|
||
(in which case the function callssetstate(eofbit),
|
||
which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")));
|
||
|
||
- [(25.3)](#25.3)
|
||
|
||
traits::eq_int_type(traits::to_int_type(c), delim) for the next available input character c (in which case c is extracted)[.](#25.sentence-3)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
The last condition will never occur iftraits::eq_int_type(delim, traits::eof())[.](#25.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
[26](#26)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5417)
|
||
|
||
*Returns*: *this[.](#26.sentence-1)
|
||
|
||
[ð](#lib:ignore,basic_istream_)
|
||
|
||
`basic_istream& ignore(streamsize n, char_type delim);
|
||
`
|
||
|
||
[27](#27)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5428)
|
||
|
||
*Constraints*: is_same_v<char_type, char> is true[.](#27.sentence-1)
|
||
|
||
[28](#28)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5432)
|
||
|
||
*Effects*: Equivalent to: return ignore(n, traits::to_int_type(delim));
|
||
|
||
[ð](#lib:peek,basic_istream)
|
||
|
||
`int_type peek();
|
||
`
|
||
|
||
[29](#29)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5443)
|
||
|
||
*Effects*: Behaves as an unformatted input function
|
||
(as described above)[.](#29.sentence-1)
|
||
|
||
After constructing a sentry object, reads but does not extract
|
||
the current input character[.](#29.sentence-2)
|
||
|
||
[30](#30)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5450)
|
||
|
||
*Returns*: traits::eof() ifgood() isfalse[.](#30.sentence-1)
|
||
|
||
Otherwise, returnsrdbuf()->sgetc()[.](#30.sentence-2)
|
||
|
||
[ð](#lib:read,basic_istream)
|
||
|
||
`basic_istream& read(char_type* s, streamsize n);
|
||
`
|
||
|
||
[31](#31)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5467)
|
||
|
||
*Effects*: Behaves as an unformatted input function (as described above)[.](#31.sentence-1)
|
||
|
||
After constructing
|
||
a sentry object, if!good() callssetstate(failbit) which may throw an exception,
|
||
and return[.](#31.sentence-2)
|
||
|
||
Otherwise extracts characters and stores them
|
||
into successive locations of an array whose first element is designated bys[.](#31.sentence-3)[282](#footnote-282 "Note that this function is not overloaded on types signed char and unsigned char.")
|
||
|
||
Characters are extracted and stored until either of the following occurs:
|
||
|
||
- [(31.1)](#31.1)
|
||
|
||
n characters are stored;
|
||
|
||
- [(31.2)](#31.2)
|
||
|
||
end-of-file occurs on the input sequence
|
||
(in which case the function callssetstate(failbit | eofbit),
|
||
which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")))[.](#31.sentence-4)
|
||
|
||
[32](#32)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5498)
|
||
|
||
*Returns*: *this[.](#32.sentence-1)
|
||
|
||
[ð](#lib:readsome,basic_istream)
|
||
|
||
`streamsize readsome(char_type* s, streamsize n);
|
||
`
|
||
|
||
[33](#33)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5509)
|
||
|
||
*Effects*: Behaves as an unformatted input function (as described above)[.](#33.sentence-1)
|
||
|
||
After constructing
|
||
a sentry object, if!good() callssetstate(failbit) which may throw an exception,
|
||
and return[.](#33.sentence-2)
|
||
|
||
Otherwise extracts characters and stores them
|
||
into successive locations of an array whose first element is designated bys[.](#33.sentence-3)
|
||
|
||
Ifrdbuf()->in_avail() == -1,
|
||
callssetstate(eofbit) (which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions"))),
|
||
and extracts no characters;
|
||
|
||
- [(33.1)](#33.1)
|
||
|
||
Ifrdbuf()->in_avail() == 0,
|
||
extracts no characters
|
||
|
||
- [(33.2)](#33.2)
|
||
|
||
Ifrdbuf()->in_avail() > 0,
|
||
extractsmin(rdbuf()->in_avail(), n))[.](#33.sentence-4)
|
||
|
||
[34](#34)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5541)
|
||
|
||
*Returns*: The number of characters extracted[.](#34.sentence-1)
|
||
|
||
[ð](#lib:putback,basic_istream)
|
||
|
||
`basic_istream& putback(char_type c);
|
||
`
|
||
|
||
[35](#35)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5552)
|
||
|
||
*Effects*: Behaves as an unformatted input function (as described above), except that the function first clears eofbit[.](#35.sentence-1)
|
||
|
||
After constructing
|
||
a sentry object, if!good() callssetstate(failbit) which may throw an exception,
|
||
and return[.](#35.sentence-2)
|
||
|
||
Ifrdbuf() is not null, callsrdbuf()->sputbackc(c)[.](#35.sentence-3)
|
||
|
||
Ifrdbuf() is null, or ifsputbackc returnstraits::eof(),
|
||
callssetstate(badbit) (which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")))[.](#35.sentence-4)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
This
|
||
function extracts no characters, so the value returned by the next call togcount() is 0[.](#35.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
[36](#36)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5583)
|
||
|
||
*Returns*: *this[.](#36.sentence-1)
|
||
|
||
[ð](#lib:unget,basic_istream)
|
||
|
||
`basic_istream& unget();
|
||
`
|
||
|
||
[37](#37)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5594)
|
||
|
||
*Effects*: Behaves as an unformatted input function (as described above), except that the function first clears eofbit[.](#37.sentence-1)
|
||
|
||
After constructing
|
||
a sentry object, if!good() callssetstate(failbit) which may throw an exception,
|
||
and return[.](#37.sentence-2)
|
||
|
||
Ifrdbuf() is not null, callsrdbuf()->sungetc()[.](#37.sentence-3)
|
||
|
||
Ifrdbuf() is null, or ifsungetc returnstraits::eof(),
|
||
callssetstate(badbit) (which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")))[.](#37.sentence-4)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
This
|
||
function extracts no characters, so the value returned by the next call togcount() is 0[.](#37.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
[38](#38)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5625)
|
||
|
||
*Returns*: *this[.](#38.sentence-1)
|
||
|
||
[ð](#lib:sync,basic_istream)
|
||
|
||
`int sync();
|
||
`
|
||
|
||
[39](#39)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5636)
|
||
|
||
*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()[.](#39.sentence-1)
|
||
|
||
After constructing
|
||
a sentry object, ifrdbuf() is a null pointer, returns -1[.](#39.sentence-2)
|
||
|
||
Otherwise, callsrdbuf()->pubsync() and, if that function returns -1 callssetstate(badbit) (which may throwios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")),
|
||
and returns-1[.](#39.sentence-3)
|
||
|
||
Otherwise, returns zero[.](#39.sentence-4)
|
||
|
||
[ð](#lib:tellg,basic_istream)
|
||
|
||
`pos_type tellg();
|
||
`
|
||
|
||
[40](#40)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5664)
|
||
|
||
*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()[.](#40.sentence-1)
|
||
|
||
[41](#41)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5671)
|
||
|
||
*Returns*: After constructing a sentry object, iffail() != false,
|
||
returnspos_type(-1) to indicate failure[.](#41.sentence-1)
|
||
|
||
Otherwise, returnsrdbuf()->pubseekoff(0, cur, in)[.](#41.sentence-2)
|
||
|
||
[ð](#lib:seekg,basic_istream)
|
||
|
||
`basic_istream& seekg(pos_type pos);
|
||
`
|
||
|
||
[42](#42)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5688)
|
||
|
||
*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()[.](#42.sentence-1)
|
||
|
||
After constructing a sentry object, iffail() != true,
|
||
executesrdbuf()->pubseekpos(pos, ios_base::in)[.](#42.sentence-2)
|
||
|
||
In case of failure, the function callssetstate(failbit) (which may throwios_base::failure)[.](#42.sentence-3)
|
||
|
||
[43](#43)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5705)
|
||
|
||
*Returns*: *this[.](#43.sentence-1)
|
||
|
||
[ð](#lib:seekg,basic_istream_)
|
||
|
||
`basic_istream& seekg(off_type off, ios_base::seekdir dir);
|
||
`
|
||
|
||
[44](#44)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5716)
|
||
|
||
*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()[.](#44.sentence-1)
|
||
|
||
After constructing a sentry object, iffail() != true,
|
||
executesrdbuf()->pubseekoff(off, dir, ios_base::in)[.](#44.sentence-2)
|
||
|
||
In case of failure, the function calls setstate(failbit) (which may throwios_base::failure)[.](#44.sentence-3)
|
||
|
||
[45](#45)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5728)
|
||
|
||
*Returns*: *this[.](#45.sentence-1)
|
||
|
||
[276)](#footnote-276)[276)](#footnoteref-276)
|
||
|
||
Note
|
||
that this function is not overloaded on typessigned char andunsigned char[.](#footnote-276.sentence-1)
|
||
|
||
[277)](#footnote-277)[277)](#footnoteref-277)
|
||
|
||
Note that this function is not overloaded on typessigned char andunsigned char[.](#footnote-277.sentence-1)
|
||
|
||
[278)](#footnote-278)[278)](#footnoteref-278)
|
||
|
||
Note that this function is not overloaded on typessigned char andunsigned char[.](#footnote-278.sentence-1)
|
||
|
||
[279)](#footnote-279)[279)](#footnoteref-279)
|
||
|
||
Since
|
||
the final input character is âextractedâ,
|
||
it is counted in thegcount(),
|
||
even though it is not stored[.](#footnote-279.sentence-1)
|
||
|
||
[280)](#footnote-280)[280)](#footnoteref-280)
|
||
|
||
This allows an input
|
||
line which exactly fills the buffer, without settingfailbit[.](#footnote-280.sentence-1)
|
||
|
||
This is different behavior than the historical AT&T implementation[.](#footnote-280.sentence-2)
|
||
|
||
[281)](#footnote-281)[281)](#footnoteref-281)
|
||
|
||
This implies an
|
||
empty input line will not causefailbit to be set[.](#footnote-281.sentence-1)
|
||
|
||
[282)](#footnote-282)[282)](#footnoteref-282)
|
||
|
||
Note that this function is not overloaded on typessigned char andunsigned char[.](#footnote-282.sentence-1)
|