namespace std { template <class charT, class traits = char_traits<charT> > class basic_istream; typedef basic_istream<char> istream; typedef basic_istream<wchar_t> wistream; template <class charT, class traits = char_traits<charT> > class basic_iostream; typedef basic_iostream<char> iostream; typedef basic_iostream<wchar_t> wiostream; template <class charT, class traits> basic_istream<charT,traits>& ws(basic_istream<charT,traits>& is); template <class charT, class traits, class T> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&& is, T& x); }
namespace std { template <class charT, class traits = char_traits<charT> > class basic_ostream; typedef basic_ostream<char> ostream; typedef basic_ostream<wchar_t> wostream; template <class charT, class traits> basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); template <class charT, class traits> basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); template <class charT, class traits> basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); template <class charT, class traits, class T> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&& os, const T& x); }
namespace std {
// types T1, T2, ... are unspecified implementation types
T1 resetiosflags(ios_base::fmtflags mask);
T2 setiosflags (ios_base::fmtflags mask);
T3 setbase(int base);
template<charT> T4 setfill(charT c);
T5 setprecision(int n);
T6 setw(int n);
template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
template <class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
}
The header <istream> defines two types and a function signature that control input from a stream buffer along with a function template that extracts from stream rvalues.
namespace std { template <class charT, class traits = char_traits<charT> > class basic_istream : virtual public basic_ios<charT,traits> { public: // types (inherited from basic_ios ([ios])): typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef traits traits_type; // [istream.cons] Constructor/destructor: explicit basic_istream(basic_streambuf<charT,traits>* sb); virtual ~basic_istream(); // [istream::sentry] Prefix/suffix: class sentry; // [istream.formatted] Formatted input: basic_istream<charT,traits>& operator>>( basic_istream<charT,traits>& (*pf)(basic_istream<charT,traits>&)); basic_istream<charT,traits>& operator>>( basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&)); basic_istream<charT,traits>& operator>>( ios_base& (*pf)(ios_base&)); basic_istream<charT,traits>& operator>>(bool& n); basic_istream<charT,traits>& operator>>(short& n); basic_istream<charT,traits>& operator>>(unsigned short& n); basic_istream<charT,traits>& operator>>(int& n); basic_istream<charT,traits>& operator>>(unsigned int& n); basic_istream<charT,traits>& operator>>(long& n); basic_istream<charT,traits>& operator>>(unsigned long& n); basic_istream<charT,traits>& operator>>(long long& n); basic_istream<charT,traits>& operator>>(unsigned long long& n); basic_istream<charT,traits>& operator>>(float& f); basic_istream<charT,traits>& operator>>(double& f); basic_istream<charT,traits>& operator>>(long double& f); basic_istream<charT,traits>& operator>>(void*& p); basic_istream<charT,traits>& operator>>( basic_streambuf<char_type,traits>* sb); // [istream.unformatted] Unformatted input: streamsize gcount() const; int_type get(); basic_istream<charT,traits>& get(char_type& c); basic_istream<charT,traits>& get(char_type* s, streamsize n); basic_istream<charT,traits>& get(char_type* s, streamsize n, char_type delim); basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb); basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb, char_type delim); basic_istream<charT,traits>& getline(char_type* s, streamsize n); basic_istream<charT,traits>& getline(char_type* s, streamsize n, char_type delim); basic_istream<charT,traits>& ignore( streamsize n = 1, int_type delim = traits::eof()); int_type peek(); basic_istream<charT,traits>& read (char_type* s, streamsize n); streamsize readsome(char_type* s, streamsize n); basic_istream<charT,traits>& putback(char_type c); basic_istream<charT,traits>& unget(); int sync(); pos_type tellg(); basic_istream<charT,traits>& seekg(pos_type); basic_istream<charT,traits>& seekg(off_type, ios_base::seekdir); protected: basic_istream(const basic_istream& rhs) = delete; basic_istream(basic_istream&& rhs); // [istream.assign] Assign/swap: basic_istream& operator=(const basic_istream& rhs) = delete; basic_istream& operator=(basic_istream&& rhs); void swap(basic_istream& rhs); }; // [istream::extractors] character extraction templates: template<class charT, class traits> basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&); template<class traits> basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&); template<class traits> basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&); template<class charT, class traits> basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*); template<class traits> basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*); template<class traits> basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*); }
The class basic_istream defines a number of member function signatures that assist in reading and interpreting input from sequences controlled by a stream buffer.
Two groups of member function signatures share common properties: the formatted input functions (or extractors) and the unformatted input functions. Both groups of input functions are described as if they obtain (or extract) input characters by calling rdbuf()->sbumpc() or rdbuf()->sgetc(). They may use other public members of istream.
If rdbuf()->sbumpc() or rdbuf()->sgetc() returns traits::eof(), then the input function, except as explicitly noted otherwise, completes its actions and does setstate(eofbit), which may throw ios_base::failure ([iostate.flags]), before returning.
If one of these called functions throws an exception, then unless explicitly noted otherwise, the input function sets badbit in error state. If badbit is on in exceptions(), the input function rethrows the exception without completing its actions, otherwise it does not throw anything and proceeds as if the called function had returned a failure indication.
explicit basic_istream(basic_streambuf<charT,traits>* sb);
Effects: Constructs an object of class basic_istream, assigning initial values to the base class by calling basic_ios::init(sb) ([basic.ios.cons]).
Postcondition: gcount() == 0
basic_istream(basic_istream&& rhs);
Effects: Move constructs from the rvalue rhs. This is accomplished by default constructing the base class, copying the gcount() from rhs, calling basic_ios<charT, traits>::move(rhs) to initialize the base class, and setting the gcount() for rhs to 0.
Effects: Destroys an object of class basic_istream.
Remarks: Does not perform any operations of rdbuf().
basic_istream& operator=(basic_istream&& rhs);
Effects: swap(rhs);.
Returns: *this.
void swap(basic_istream& rhs);
Effects: Calls basic_ios<charT, traits>::swap(rhs). Exchanges the values returned by gcount() and rhs.gcount().
namespace std {
template <class charT,class traits = char_traits<charT> >
class basic_istream<charT,traits>::sentry {
typedef traits traits_type;
bool ok_; // exposition only
public:
explicit sentry(basic_istream<charT,traits>& is, bool noskipws = false);
~sentry();
explicit operator bool() const { return ok_; }
sentry(const sentry&) = delete;
sentry& operator=(const sentry&) = delete;
};
}
The class sentry defines a class that is responsible for doing exception safe prefix and suffix operations.
explicit sentry(basic_istream<charT,traits>& is, bool noskipws = false);
Effects: If is.good() is false, calls is.setstate(failbit). Otherwise, prepares for formatted or unformatted input. First, if is.tie() is not a null pointer, the function calls is.tie()->flush() to synchronize the output sequence with any associated external C stream. Except that this call can be suppressed if the put area of is.tie() is empty. Further an implementation is allowed to defer the call to flush until a call of is.rdbuf()->underflow() occurs. If no such call occurs before the sentry object is destroyed, the call to flush may be eliminated entirely.312 If noskipws is zero and is.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. If is.rdbuf()->sbumpc() or is.rdbuf()->sgetc() returns traits::eof(), the function calls setstate(failbit | eofbit) (which may throw ios_base::failure).
Remarks: The constructor explicit sentry(basic_istream<charT,traits>& is, bool noskipws = false) uses the currently imbued locale in is, to determine whether the next input character is whitespace or not.
To decide if the character c is a whitespace character, the constructor performs as if it executes the following code fragment:
const ctype<charT>& ctype = use_facet<ctype<charT> >(is.getloc());
if (ctype.is(ctype.space,c)!=0)
// c is a whitespace character.
If, after any preparation is completed, is.good() is true, ok_ != false otherwise, ok_ == false. During preparation, the constructor may call setstate(failbit) (which may throw ios_base::failure ([iostate.flags]))313
Effects: None.
explicit operator bool() const;
Effects: Returns ok_.
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.
Each formatted input function begins execution by constructing an object of class sentry with the noskipws (second) argument false. If the sentry object returns true, when converted to a value of type bool, the function endeavors to obtain the requested input. If an exception is thrown during input then ios::badbit is turned on314 in *this's error state. If (exceptions()&badbit) != 0 then the exception is rethrown. In any case, the formatted input function destroys the sentry object. If no exception has been thrown, it returns *this.
This is done without causing an ios::failure to be thrown.
operator>>(unsigned short& val);
operator>>(unsigned int& val);
operator>>(long& val);
operator>>(unsigned long& val);
operator>>(long long& val);
operator>>(unsigned long long& val);
operator>>(float& val);
operator>>(double& val);
operator>>(long double& val);
operator>>(bool& val);
operator>>(void*& val);
As in the case of the inserters, these extractors depend on the locale's num_get<> ([locale.num.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:
typedef num_get< charT,istreambuf_iterator<charT,traits> > numget; iostate err = iostate::goodbit; use_facet< numget >(loc).get(*this, 0, *this, err, val); setstate(err);
In the above fragment, loc stands for the private member of the basic_ios class. [ Note: The first argument provides an object of the istreambuf_iterator class which is an iterator pointed to an input stream. It bypasses istreams and uses streambufs directly. — end note ] Class locale relies on this type as its interface to istream, so that it does not need to depend directly on istream.
The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):
typedef num_get<charT,istreambuf_iterator<charT,traits> > numget; iostate err = ios_base::goodbit; long lval; use_facet<numget>(loc).get(*this, 0, *this, err, lval); if (lval < numeric_limits<short>::min()) { err |= ios_base::failbit; val = numeric_limits<short>::min(); } else if (numeric_limits<short>::max() < lval) { err |= ios_base::failbit; val = numeric_limits<short>::max(); } else val = static_cast<short>(lval); setstate(err);
The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):
typedef num_get<charT,istreambuf_iterator<charT,traits> > numget; iostate err = ios_base::goodbit; long lval; use_facet<numget>(loc).get(*this, 0, *this, err, lval); if (lval < numeric_limits<int>::min()) { err |= ios_base::failbit; val = numeric_limits<int>::min(); } else if (numeric_limits<int>::max() < lval) { err |= ios_base::failbit; val = numeric_limits<int>::max(); } else val = static_cast<int>(lval); setstate(err);
basic_istream<charT,traits>& operator>>
(basic_istream<charT,traits>& (*pf)(basic_istream<charT,traits>&))
Effects: None. This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts].)
basic_istream<charT,traits>& operator>>
(basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&));
Effects: Calls pf(*this). This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts]).
Returns: *this.
basic_istream<charT,traits>& operator>>
(ios_base& (*pf)(ios_base&));
Effects: Calls pf(*this).316 This extractor does not behave as a formatted input function (as described in [istream.formatted.reqmts]).
Returns: *this.
template<class charT, class traits>
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>& in,
charT* s);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
unsigned char* s);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
signed char* s);
Effects: Behaves like a formatted input member (as described in [istream.formatted.reqmts]) of in. After a sentry object is constructed, operator>> extracts characters and stores them into successive locations of an array whose first element is designated by s. If width() is greater than zero, n is width(). Otherwise n is the number of elements of the largest array of char_type that can store a terminating charT(). n is the maximum number of characters stored.
operator>> then stores a null byte (charT()) in the next position, which may be the first position if no characters were extracted. operator>> then calls width(0).
If the function extracted no characters, it calls setstate(failbit), which may throw ios_base::failure ([iostate.flags]).
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);
Effects: Behaves like a formatted input member (as described in [istream.formatted.reqmts]) of in. After a sentry object is constructed a character is extracted from in, if one is available, and stored in c. Otherwise, the function calls in.setstate(failbit).
Returns: in.
basic_istream<charT,traits>& operator>>
(basic_streambuf<charT,traits>* sb);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). If sb is null, calls setstate(failbit), which may throw ios_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).
If the function inserts no characters, it calls setstate(failbit), which may throw ios_base::failure ([iostate.flags]). If it inserted no characters because it caught an exception thrown while extracting characters from *this and failbit is on in exceptions() ([iostate.flags]), then the caught exception is rethrown.
Returns: *this.
See, for example, the function signature ws(basic_istream&) ([istream.manip]).
See, for example, the function signature dec(ios_base&) ([basefield.manip]).
Each unformatted input function begins execution by constructing an object of class sentry with the default argument noskipws (second) argument true. If the sentry object returns true, when converted to a value of type bool, the function endeavors to obtain the requested input. Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object returns false, when converted to a value of type bool, 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 non-zero size as an argument shall also store a null character (using charT()) in the first location of the array. If an exception is thrown during input then ios::badbit is turned on317 in *this's error state. (Exceptions thrown from basic_ios<>::clear() are not caught or rethrown.) If (exceptions()&badbit) != 0 then the exception is rethrown. It also counts the number of characters extracted. If no exception has been thrown it ends by storing the count in a member object and returning the value specified. In any event the sentry object is destroyed before leaving the unformatted input function.
Effects: None. This member function does not behave as an unformatted input function (as described in [istream.unformatted], paragraph 1).
Returns: The number of characters extracted by the last unformatted input member function called for the object.
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts a character c, if one is available. Otherwise, the function calls setstate(failbit), which may throw ios_base::failure ([iostate.flags]),
Returns: c if available, otherwise traits::eof().
basic_istream<charT,traits>& get(char_type& c);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts a character, if one is available, and assigns it to c.318 Otherwise, the function calls setstate(failbit) (which may throw ios_base::failure ([iostate.flags])).
Returns: *this.
basic_istream<charT,traits>& get(char_type* s, streamsize n,
char_type delim );
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated by s.319 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 (in which case the function calls setstate(eofbit));
traits::eq(c, delim) for the next available input character c (in which case c is not extracted).
If the function stores no characters, it calls setstate(failbit) (which may throw ios_base::failure ([iostate.flags])). In any case, if n is greater than zero it then stores a null character into the next successive location of the array.
Returns: *this.
basic_istream<charT,traits>& get(char_type* s, streamsize n)
Effects: Calls get(s,n,widen('\n'))
Returns: Value returned by the call.
basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
char_type delim );
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts characters 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);
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).
If the function inserts no characters, it calls setstate(failbit), which may throw ios_base::failure ([iostate.flags]).
Returns: *this.
basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb);
Effects: Calls get(sb, widen('\n'))
Returns: Value returned by the call.
basic_istream<charT,traits>& getline(char_type* s, streamsize n,
char_type delim);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated by s.320 Characters are extracted and stored until one of the following occurs:
end-of-file occurs on the input sequence (in which case the function calls setstate(eofbit));
traits::eq(c, delim) for the next available input character c (in which case the input character is extracted but not stored);321
n is less than one or n - 1 characters are stored (in which case the function calls setstate(failbit)).
If the function extracts no characters, it calls setstate(failbit) (which may throw ios_base::failure ([iostate.flags])).323
In any case, if n is greater than zero, it then stores a null character (using charT()) into the next successive location of the array.
Returns: *this.
[ Example:
#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 false else 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<charT,traits>& getline(char_type* s, streamsize n);
Returns: getline(s,n,widen('\n'))
basic_istream<charT,traits>&
ignore(streamsize n = 1, int_type delim = traits::eof());
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, extracts characters and discards them. Characters are extracted until any of the following occurs:
if n != numeric_limits<streamsize>::max() ([limits]), n characters are extracted
end-of-file occurs on the input sequence (in which case the function calls setstate(eofbit), which may throw ios_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).
Remarks: The last condition will never occur if traits::eq_int_type(delim, traits::eof()).
Returns: *this.
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, reads but does not extract the current input character.
Returns: traits::eof() if good() is false. Otherwise, returns rdbuf()->sgetc().
basic_istream<charT,traits>& read(char_type* s, streamsize n);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, if !good() calls setstate(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 by s.324 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 calls setstate(failbit | eofbit), which may throw ios_base::failure ([iostate.flags])).
Returns: *this.
streamsize readsome(char_type* s, streamsize n);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1). After constructing a sentry object, if !good() calls setstate(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 by s. If rdbuf()->in_avail() == -1, calls setstate(eofbit) (which may throw ios_base::failure ([iostate.flags])), and extracts no characters;
If rdbuf()->in_avail() == 0, extracts no characters
If rdbuf()->in_avail() > 0, extracts min(rdbuf()->in_avail(),n)).
Returns: The number of characters extracted.
basic_istream<charT,traits>& putback(char_type c);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), except that the function first clears eofbit. After constructing a sentry object, if !good() calls setstate(failbit) which may throw an exception, and return. If rdbuf() is not null, calls rdbuf->sputbackc(). If rdbuf() is null, or if sputbackc() returns traits::eof(), calls setstate(badbit) (which may throw ios_base::failure ([iostate.flags])). [ Note: This function extracts no characters, so the value returned by the next call to gcount() is 0. — end note ]
Returns: *this.
basic_istream<charT,traits>& unget();
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), except that the function first clears eofbit. After constructing a sentry object, if !good() calls setstate(failbit) which may throw an exception, and return. If rdbuf() is not null, calls rdbuf()->sungetc(). If rdbuf() is null, or if sungetc() returns traits::eof(), calls setstate(badbit) (which may throw ios_base::failure ([iostate.flags])). [ Note: This function extracts no characters, so the value returned by the next call to gcount() is 0. — end note ]
Returns: *this.
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), except that it 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, if rdbuf() is a null pointer, returns -1 . Otherwise, calls rdbuf()->pubsync() and, if that function returns -1 calls setstate(badbit) (which may throw ios_base::failure ([iostate.flags]), and returns -1. Otherwise, returns zero.
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls to gcount().
Returns: After constructing a sentry object, if fail() != false, returns pos_type(-1) to indicate failure. Otherwise, returns rdbuf()->pubseekoff(0, cur, in).
basic_istream<charT,traits>& seekg(pos_type pos);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), 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 to gcount(). After constructing a sentry object, if fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::in). In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).
Returns: *this.
basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), except that it 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, if fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::in). In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).
Returns: *this.
This is done without causing an ios::failure to be thrown.
Note that this function is not overloaded on types signed char and unsigned char.
Note that this function is not overloaded on types signed char and unsigned char.
Note that this function is not overloaded on types signed char and unsigned char.
Since the final input character is “extracted,” it is counted in the gcount(), even though it is not stored.
This allows an input line which exactly fills the buffer, without setting failbit. This is different behavior than the historical AT&T implementation.
This implies an empty input line will not cause failbit to be set.
Note that this function is not overloaded on types signed char and unsigned char.
namespace std {
template <class charT, class traits>
basic_istream<charT,traits>& ws(basic_istream<charT,traits>& is);
}
Effects: Behaves as an unformatted input function (as described in [istream.unformatted], paragraph 1), 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 by sentry::sentry ([istream::sentry]). If ws stops extracting characters because there are no more available it sets eofbit, but not failbit.
Returns: is.
namespace std { template <class charT, class traits = char_traits<charT> > class basic_iostream : public basic_istream<charT,traits>, public basic_ostream<charT,traits> { public: // types: typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef traits traits_type; // constructor/destructor explicit basic_iostream(basic_streambuf<charT,traits>* sb); virtual ~basic_iostream(); protected: basic_iostream(const basic_iostream& rhs) = delete; basic_iostream(basic_iostream&& rhs); // assign/swap basic_iostream& operator=(const basic_iostream& rhs) = delete; basic_iostream& operator=(basic_iostream&& rhs); void swap(basic_iostream& rhs); }; }
The class basic_iostream inherits a number of functions that allow reading input and writing output to sequences controlled by a stream buffer.
explicit basic_iostream(basic_streambuf<charT,traits>* sb);
basic_iostream(basic_iostream&& rhs);
Effects: Move constructs from the rvalue rhs by constructing the basic_istream base class with move(rhs).
Effects: Destroys an object of class basic_iostream.
Remarks: Does not perform any operations on rdbuf().
basic_iostream& operator=(basic_iostream&& rhs);
Effects: swap(rhs).
void swap(basic_iostream& rhs);
Effects: Calls basic_istream<charT, traits>::swap(rhs).
template <class charT, class traits, class T>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>&& is, T& x);
Effects: is >> x
Returns: is
The header <ostream> defines a type and several function signatures that control output to a stream buffer along with a function template that inserts into stream rvalues.
namespace std { template <class charT, class traits = char_traits<charT> > class basic_ostream : virtual public basic_ios<charT,traits> { public: // types (inherited from basic_ios ([ios])): typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef traits traits_type; // [ostream.cons] Constructor/destructor: explicit basic_ostream(basic_streambuf<char_type,traits>* sb); virtual ~basic_ostream(); // [ostream::sentry] Prefix/suffix: class sentry; // [ostream.formatted] Formatted output: basic_ostream<charT,traits>& operator<<( basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&)); basic_ostream<charT,traits>& operator<<( basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&)); basic_ostream<charT,traits>& operator<<( ios_base& (*pf)(ios_base&)); basic_ostream<charT,traits>& operator<<(bool n); basic_ostream<charT,traits>& operator<<(short n); basic_ostream<charT,traits>& operator<<(unsigned short n); basic_ostream<charT,traits>& operator<<(int n); basic_ostream<charT,traits>& operator<<(unsigned int n); basic_ostream<charT,traits>& operator<<(long n); basic_ostream<charT,traits>& operator<<(unsigned long n); basic_ostream<charT,traits>& operator<<(long long n); basic_ostream<charT,traits>& operator<<(unsigned long long n); basic_ostream<charT,traits>& operator<<(float f); basic_ostream<charT,traits>& operator<<(double f); basic_ostream<charT,traits>& operator<<(long double f); basic_ostream<charT,traits>& operator<<(const void* p); basic_ostream<charT,traits>& operator<<( basic_streambuf<char_type,traits>* sb); // [ostream.unformatted] Unformatted output: basic_ostream<charT,traits>& put(char_type c); basic_ostream<charT,traits>& write(const char_type* s, streamsize n); basic_ostream<charT,traits>& flush(); // [ostream.seeks] seeks: pos_type tellp(); basic_ostream<charT,traits>& seekp(pos_type); basic_ostream<charT,traits>& seekp(off_type, ios_base::seekdir); protected: basic_ostream(const basic_ostream& rhs) = delete; basic_ostream(basic_ostream&& rhs); // [ostream.assign] Assign/swap basic_ostream& operator=(basic_ostream& rhs) = delete; basic_ostream& operator=(const basic_ostream&& rhs); void swap(basic_ostream& rhs); }; // [ostream.inserters.character] character inserters template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT); template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char); template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char); // signed and unsigned template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char); template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char); template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*); template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*); // signed and unsigned template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*); template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*); }
The class basic_ostream defines a number of member function signatures that assist in formatting and writing output to output sequences controlled by a stream buffer.
Two groups of member function signatures share common properties: the formatted output functions (or inserters) and the unformatted output functions. Both groups of output functions generate (or insert) output characters by actions equivalent to calling rdbuf()->sputc(int_type). They may use other public members of basic_ostream except that they shall not invoke any virtual members of rdbuf() except overflow(), xsputn(), and sync().
If one of these called functions throws an exception, then unless explicitly noted otherwise the output function sets badbit in error state. If badbit is on in exceptions(), the output function rethrows the exception without completing its actions, otherwise it does not throw anything and treat as an error.
explicit basic_ostream(basic_streambuf<charT,traits>* sb);
Effects: Constructs an object of class basic_ostream, assigning initial values to the base class by calling basic_ios<charT,traits>::init(sb) ([basic.ios.cons]).
Effects: Destroys an object of class basic_ostream.
Remarks: Does not perform any operations on rdbuf().
basic_ostream(basic_ostream&& rhs);
Effects: Move constructs from the rvalue rhs. This is accomplished by default constructing the base class and calling basic_ios<charT, traits>::move(rhs) to initialize the base class.
basic_ostream& operator=(basic_ostream&& rhs);
Effects: swap(rhs).
Returns: *this.
void swap(basic_ostream& rhs);
Effects: Calls basic_ios<charT, traits>::swap(rhs).
namespace std {
template <class charT,class traits = char_traits<charT> >
class basic_ostream<charT,traits>::sentry {
bool ok_; // exposition only
public:
explicit sentry(basic_ostream<charT,traits>& os);
~sentry();
explicit operator bool() const { return ok_; }
sentry(const sentry&) = delete;
sentry& operator=(const sentry&) = delete;
};
}
The class sentry defines a class that is responsible for doing exception safe prefix and suffix operations.
If os.good() is nonzero, prepares for formatted or unformatted output. If os.tie() is not a null pointer, calls os.tie()->flush().325
If, after any preparation is completed, os.good() is true, ok_ == true otherwise, ok_ == false. During preparation, the constructor may call setstate(failbit) (which may throw ios_base::failure ([iostate.flags]))326
If ((os.flags() & ios_base::unitbuf) && !uncaught_exception() && os.good()) is true, calls os.rdbuf()->pubsync(). If that function returns -1, sets badbit in os.rdstate() without propagating an exception.
explicit operator bool() const;
Effects: Returns ok_.
The call os.tie()->flush() does not necessarily occur if the function can determine that no synchronization is necessary.
The sentry constructor and destructor can also perform additional implementation-dependent operations.
Each seek member function begins execution by constructing an object of class sentry. It returns by destroying the sentry object.
Returns:
If
fail() != false,
returns
pos_type(-1)
to indicate failure.
Otherwise, returns
rdbuf()->pubseekoff(0, cur, out).
basic_ostream<charT,traits>& seekp(pos_type pos);
Effects: If fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::out). In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).
Returns: *this.
basic_ostream<charT,traits>& seekp(off_type off, ios_base::seekdir dir);
Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::out).
Returns: *this.
Each formatted output function begins execution by constructing an object of class sentry. If this object returns true when converted to a value of type bool, the function endeavors to generate the requested output. If the generation fails, then the formatted output function does setstate(ios_base::failbit), which might throw an exception. If an exception is thrown during output, then ios::badbit is turned on327 in *this's error state. If (exceptions()&badbit) != 0 then the exception is rethrown. Whether or not an exception is thrown, the sentry object is destroyed before leaving the formatted output function. If no exception is thrown, the result of the formatted output function is *this.
The descriptions of the individual formatted output operations describe how they perform output and do not mention the sentry object.
without causing an ios::failure to be thrown.
operator<<(bool val);
operator<<(short val);
operator<<(unsigned short val);
operator<<(int val);
operator<<(unsigned int val);
operator<<(long val);
operator<<(unsigned long val);
operator<<(long long val);
operator<<(unsigned long long val);
operator<<(float val);
operator<<(double val);
operator<<(long double val);
operator<<(const void* val);
Effects: The classes num_get<> and num_put<> handle locale-dependent numeric formatting and parsing. These inserter functions use the imbued locale value to perform numeric formatting. When val is of type bool, long, unsigned long, long long, unsigned long long, double, long double, or const void*, the formatting conversion occurs as if it performed the following code fragment:
bool failed = use_facet< num_put<charT,ostreambuf_iterator<charT,traits> > >(getloc()).put(*this, *this, fill(), val).failed();
When val is of type short the formatting conversion occurs as if it performed the following code fragment:
ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield; bool failed = use_facet< num_put<charT,ostreambuf_iterator<charT,traits> > >(getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex ? static_cast<long>(static_cast<unsigned short>(val)) : static_cast<long>(val)).failed();
When val is of type int the formatting conversion occurs as if it performed the following code fragment:
ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield; bool failed = use_facet< num_put<charT,ostreambuf_iterator<charT,traits> > >(getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex ? static_cast<long>(static_cast<unsigned int>(val)) : static_cast<long>(val)).failed();
When val is of type unsigned short or unsigned int the formatting conversion occurs as if it performed the following code fragment:
bool failed = use_facet< num_put<charT,ostreambuf_iterator<charT,traits> > >(getloc()).put(*this, *this, fill(), static_cast<unsigned long>(val)).failed();
When val is of type float the formatting conversion occurs as if it performed the following code fragment:
bool failed = use_facet< num_put<charT,ostreambuf_iterator<charT,traits> > >(getloc()).put(*this, *this, fill(), static_cast<double>(val)).failed();
The first argument provides an object of the ostreambuf_iterator<> class which is an iterator for class basic_ostream<>. It bypasses ostreams and uses streambufs directly. Class locale relies on these types as its interface to iostreams, since for flexibility it has been abstracted away from direct dependence on ostream. The second parameter is a reference to the base subobject of type ios_base. It provides formatting specifications such as field width, and a locale from which to obtain other facets. If failed is true then does setstate(badbit), which may throw an exception, and returns.
Returns: *this.
basic_ostream<charT,traits>& operator<<
(basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&))
Effects: None. Does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).
basic_ostream<charT,traits>& operator<<
(basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&))
Effects: Calls pf(*this). This inserter does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).
basic_ostream<charT,traits>& operator<<
(ios_base& (*pf)(ios_base&))
Effects: Calls pf(*this). This inserter does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).
Returns: *this.
basic_ostream<charT,traits>& operator<<
(basic_streambuf<charT,traits>* sb);
Effects: Behaves as an unformatted output function (as described in [ostream.unformatted], paragraph 1). After the sentry object is constructed, if sb is null calls setstate(badbit) (which may throw ios_base::failure).
Gets characters from sb and inserts them in *this. Characters are read from sb 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 while getting a character from sb.
If the function inserts no characters, it calls setstate(failbit) (which may throw ios_base::failure ([iostate.flags])). If an exception was thrown while extracting a character, the function sets failbit in error state, and if failbit is on in exceptions() the caught exception is rethrown.
Returns: *this.
See, for example, the function signature endl(basic_ostream&) ([ostream.manip]).
See, for example, the function signature dec(ios_base&) ([basefield.manip]).
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
charT c);
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
char c);
// specialization
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
char c);
// signed and unsigned
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
signed char c);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
unsigned char c);
Effects: Behaves like a formatted inserter (as described in [ostream.formatted.reqmts]) of out. After a sentry object is constructed it inserts characters. In case c has type char and the character type of the stream is not char, then the character to be inserted is out.widen(c); otherwise the character is c. Padding is determined as described in [facet.num.put.virtuals]. width(0) is called. The insertion character and any required padding are inserted into out.
Returns: out.
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
const charT* s);
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
const char* s);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
const char* s);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
const signed char* s);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
const unsigned char* s);
Requires: s shall not be a null pointer.
Effects: Behaves like a formatted inserter (as described in [ostream.formatted.reqmts]) of out. After a sentry object is constructed it inserts n characters starting at s, where n is the number that would be computed as if by:
traits::length(s) for the overload where the first argument is of type basic_ostream<charT, traits>& and the second is of type const charT*, and also for the overload where the first argument is of type basic_ostream<char, traits>& and the second is of type const char*,
std::char_traits<char>::length(s) for the overload where the first argument is of type basic_ostream<charT, traits>& and the second is of type const char*,
traits::length(reinterpret_cast<const char*>(s)) for the other two overloads.
Padding is determined as described in [facet.num.put.virtuals]. The n characters starting at s are widened using out.widen ([basic.ios.members]). The widened characters and any required padding are inserted into out. Calls width(0).
Returns: out.
Each unformatted output function begins execution by constructing an object of class sentry. If this object returns true, while converting to a value of type bool, the function endeavors to generate the requested output. If an exception is thrown during output, then ios::badbit is turned on330 in *this's error state. If (exceptions() & badbit) != 0 then the exception is rethrown. In any case, the unformatted output function ends by destroying the sentry object, then, if no exception was thrown, returning the value specified for the unformatted output function.
Effects: Behaves as an unformatted output function (as described in [ostream.unformatted], paragraph 1). After constructing a sentry object, inserts the character c, if possible.331
Otherwise, calls setstate(badbit) (which may throw ios_base::failure ([iostate.flags])).
Returns: *this.
basic_ostream& write(const char_type* s, streamsize n);
Effects: Behaves as an unformatted output function (as described in [ostream.unformatted], paragraph 1). After constructing a sentry object, obtains characters to insert from successive locations of an array whose first element is designated by s.332 Characters are inserted until either of the following occurs:
n characters are inserted;
inserting in the output sequence fails (in which case the function calls setstate(badbit), which may throw ios_base::failure ([iostate.flags])).
Returns: *this.
Effects: Behaves as an unformatted output function (as described in [ostream.formatted.reqmts], paragraph 1). If rdbuf() is not a null pointer, constructs a sentry object. If this object returns true when converted to a value of type bool the function calls rdbuf()->pubsync(). If that function returns -1 calls setstate(badbit) (which may throw ios_base::failure ([iostate.flags])). Otherwise, if the sentry object returns false, does nothing.
Returns: *this.
without causing an ios::failure to be thrown.
Note that this function is not overloaded on types signed char and unsigned char.
Note that this function is not overloaded on types signed char and unsigned char.
namespace std {
template <class charT, class traits>
basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
}
Effects: Calls os.put(os.widen('\n')), then os.flush().
Returns: os.
namespace std {
template <class charT, class traits>
basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
}
Effects: Inserts a null character into the output sequence: calls os.put(charT()).
Returns: os.
namespace std {
template <class charT, class traits>
basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
}
Effects: Calls os.flush().
Returns: os.
template <class charT, class traits, class T>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>&& os, const T& x);
Effects: os << x
Returns: os
The header <iomanip> defines several functions that support extractors and inserters that alter information maintained by class ios_base and its derived classes.
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << resetiosflags(mask) behaves as if it called f(out, mask), or if in is an object of type basic_istream<charT, traits> then the expression in >> resetiosflags(mask) behaves as if it called f(in, mask), where the function f is defined as:333
void f(ios_base& str, ios_base::fmtflags mask) {
// reset specified flags
str.setf(ios_base::fmtflags(0), mask);
}
The expression out << resetiosflags(mask) shall have type basic_ostream<charT,traits>& and value out. The expression in >> resetiosflags(mask) shall have type basic_istream<charT, traits>& and value in.
unspecified setiosflags(ios_base::fmtflags mask);
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << setiosflags(mask) behaves as if it called f(out, mask), or if in is an object of type basic_istream<charT, traits> then the expression in >> setiosflags(mask) behaves as if it called f(in, mask), where the function f is defined as:
void f(ios_base& str, ios_base::fmtflags mask) {
// set specified flags
str.setf(mask);
}
The expression
out << setiosflags(mask)
shall have type
basic_ostream<charT, traits>&
and value
out.
The expression
in >> setiosflags(mask)
shall have type
basic_istream<charT,
traits>&
and value
in.
unspecified setbase(int base);
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << setbase(base) behaves as if it called f(out, base), or if in is an object of type basic_istream<charT, traits> then the expression in >> setbase(base) behaves as if it called f(in, base), where the function f is defined as:
void f(ios_base& str, int base) {
// set basefield
str.setf(base == 8 ? ios_base::oct :
base == 10 ? ios_base::dec :
base == 16 ? ios_base::hex :
ios_base::fmtflags(0), ios_base::basefield);
}
The expression out << setbase(base) shall have type basic_ostream<charT, traits>& and value out. The expression in >> setbase(base) shall have type basic_istream<charT, traits>& and value in.
unspecified setfill(char_type c);
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> and c has type charT then the expression out << setfill(c) behaves as if it called f(out, c), where the function f is defined as:
template<class charT, class traits>
void f(basic_ios<charT,traits>& str, charT c) {
// set fill character
str.fill(c);
}
The expression out << setfill(c) shall have type basic_ostream<charT, traits>& and value out.
unspecified setprecision(int n);
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << setprecision(n) behaves as if it called f(out, n), or if in is an object of type basic_istream<charT, traits> then the expression in >> setprecision(n) behaves as if it called f(in, n), where the function f is defined as:
void f(ios_base& str, int n) {
// set precision
str.precision(n);
}
The expression out << setprecision(n) shall have type basic_ostream<charT, traits>& and value out. The expression in >> setprecision(n) shall have type basic_istream<charT, traits>& and value in.
Returns: An object of unspecified type such that if out is an instance of basic_ostream<charT, traits> then the expression out << setw(n) behaves as if it called f(out, n), or if in is an object of type basic_istream<charT, traits> then the expression in >> setw(n) behaves as if it called f(in, n), where the function f is defined as:
void f(ios_base& str, int n) {
// set width
str.width(n);
}
The expression out << setw(n) shall have type basic_ostream<charT, traits>& and value out. The expression in >> setw(n) shall have type basic_istream<charT, traits>& and value in.
The expression cin >> resetiosflags(ios_base::skipws) clears ios_base::skipws in the format flags stored in the basic_istream<charT,traits> object cin (the same as cin >> noskipws), and the expression cout << resetiosflags(ios_base::showbase) clears ios_base::showbase in the format flags stored in the basic_ostream<charT,traits> object cout (the same as cout << noshowbase).
The header <iomanip> defines several functions that support extractors and inserters that allow for the parsing and formatting of sequences and values for money and time.
template <class moneyT> unspecified get_money(moneyT& mon, bool intl = false);
Requires: The type moneyT shall be either long double or a specialization of the basic_string template (Clause [strings]).
Effects: The expression in >> get_money(mon, intl) described below behaves as a formatted input function ([istream.formatted.reqmts]).
Returns: An object of unspecified type such that if in is an object of type basic_istream<charT, traits> then the expression in >> get_money(mon, intl) behaves as if it called f(in, mon, intl), where the function f is defined as:
template <class charT, class traits, class moneyT> void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) { typedef istreambuf_iterator<charT, traits> Iter; typedef money_get<charT, Iter> MoneyGet; ios_base::iostate err = ios_base::goodbit; const MoneyGet &mg = use_facet<MoneyGet>(str.getloc()); mg.get(Iter(str.rdbuf()), Iter(), intl, str, err, mon); if (ios_base::goodbit != err) str.setstate(err); }
The expression in >> get_money(mon, intl) shall have type basic_istream<charT, traits>& and value in.
template <class moneyT> unspecified put_money(const moneyT& mon, bool intl = false);
Requires: The type moneyT shall be either long double or a specialization of the basic_string template (Clause [strings]).
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << put_money(mon, intl) behaves as a formatted input function that calls f(out, mon, intl), where the function f is defined as:
template <class charT, class traits, class moneyT> void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) { typedef ostreambuf_iterator<charT, traits> Iter; typedef money_put<charT, Iter> MoneyPut; const MoneyPut& mp = use_facet<MoneyPut>(str.getloc()); const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon); if (end.failed()) str.setstate(ios::badbit); }
The expression out << put_money(mon, intl) shall have type basic_ostream<charT, traits>& and value out.
template <class charT> unspecified get_time(struct tm* tmb, const charT* fmt);
Requires: The argument tmb shall be a valid pointer to an object of type struct tm, and the argument fmt shall be a valid pointer to an array of objects of type charT with char_traits<charT>::length(fmt) elements.
Returns: An object of unspecified type such that if in is an object of type basic_istream<charT, traits> then the expression in >> get_time(tmb, fmt) behaves as if it called f(in, tmb, fmt), where the function f is defined as:
template <class charT, class traits> void f(basic_ios<charT, traits>& str, struct tm* tmb, const charT* fmt) { typedef istreambuf_iterator<charT, traits> Iter; typedef time_get<charT, Iter> TimeGet; ios_base::iostate err = ios_base::goodbit; const TimeGet& tg = use_facet<TimeGet>(str.getloc()); tg.get(Iter(str.rdbuf()), Iter(), str, err, tmb, fmt, fmt + traits::length(fmt)); if (err != ios_base::goodbit) str.setstate(err): }
The expression in >> get_time(tmb, fmt) shall have type basic_istream<charT, traits>& and value in.
template <class charT> unspecified put_time(const struct tm* tmb, const charT* fmt);
Requires: The argument tmb shall be a valid pointer to an object of type struct tm, and the argument fmt shall be a valid pointer to an array of objects of type charT with char_traits<charT>::length(fmt) elements.
Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expression out << put_time(tmb, fmt) behaves as if it called f(out, tmb, fmt), where the function f is defined as:
template <class charT, class traits> void f(basic_ios<charT, traits>& str, const struct tm* tmb, const charT* fmt) { typedef ostreambuf_iterator<charT, traits> Iter; typedef time_put<charT, Iter> TimePut; const TimePut& tp = use_facet<TimePut>(str.getloc()); const Iter end = tp.put(Iter(str.rdbuf()), str, str.fill(), tmb, fmt, fmt + traits::length(fmt)); if (end.failed()) str.setstate(ios_base::badbit); }
The expression out << put_time(tmb, fmt) shall have type basic_istream<charT, traits>& and value out.