Files
2025-10-25 03:02:53 +03:00

96 lines
7.9 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[ostream.general]
# 31 Input/output library [[input.output]](./#input.output)
## 31.7 Formatting and manipulators [[iostream.format]](iostream.format#ostream.general)
### 31.7.6 Output streams [[output.streams]](output.streams#ostream.general)
#### 31.7.6.2 Class template basic_ostream [[ostream]](ostream#general)
#### 31.7.6.2.1 General [ostream.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L5921)
When a function has
a parameter type *extended-floating-point-type*,
the implementation provides overloads
for all cv-unqualified extended floating-point types ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#1.sentence-1)
[🔗](#lib:basic_ostream)
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 "31.5.4Class template basic_­ios[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; // [[ostream.cons]](ostream.cons "31.7.6.2.2Constructors"), constructor/destructorexplicit basic_ostream(basic_streambuf<char_type, traits>* sb); virtual ~basic_ostream(); // [[ostream.sentry]](ostream.sentry "31.7.6.2.4Class basic_­ostream::sentry"), prefix/suffixclass sentry; // [[ostream.formatted]](ostream.formatted "31.7.6.3Formatted output functions"), formatted output basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
basic_ostream& operator<<(bool n);
basic_ostream& operator<<(short n);
basic_ostream& operator<<(unsigned short n);
basic_ostream& operator<<(int n);
basic_ostream& operator<<(unsigned int n);
basic_ostream& operator<<(long n);
basic_ostream& operator<<(unsigned long n);
basic_ostream& operator<<(long long n);
basic_ostream& operator<<(unsigned long long n);
basic_ostream& operator<<(float f);
basic_ostream& operator<<(double f);
basic_ostream& operator<<(long double f);
basic_ostream& operator<<(*extended-floating-point-type* f);
basic_ostream& operator<<(const void* p);
basic_ostream& operator<<(const volatile void* p);
basic_ostream& operator<<(nullptr_t);
basic_ostream& operator<<(basic_streambuf<char_type, traits>* sb); // [[ostream.unformatted]](ostream.unformatted "31.7.6.4Unformatted output functions"), unformatted output basic_ostream& put(char_type c);
basic_ostream& write(const char_type* s, streamsize n);
basic_ostream& flush(); // [[ostream.seeks]](ostream.seeks "31.7.6.2.5Seek members"), seeks pos_type tellp();
basic_ostream& seekp(pos_type);
basic_ostream& seekp(off_type, ios_base::seekdir); protected:// [[ostream.cons]](ostream.cons "31.7.6.2.2Constructors"), copy/move constructor basic_ostream(const basic_ostream&) = delete;
basic_ostream(basic_ostream&& rhs); // [[ostream.assign]](ostream.assign "31.7.6.2.3Assignment and swap"), assignment and swap basic_ostream& operator=(const basic_ostream&) = delete;
basic_ostream& operator=(basic_ostream&& rhs); void swap(basic_ostream& rhs); }; // [[ostream.inserters.character]](ostream.inserters.character "31.7.6.3.4Character inserter function templates"), character inserterstemplate<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); 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 traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete; template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete; template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete; template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete; 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*); 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*); template<class traits> basic_ostream<char, traits>&operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete; template<class traits> basic_ostream<char, traits>&operator<<(basic_ostream<char, traits>&, const char8_t*) = delete; template<class traits> basic_ostream<char, traits>&operator<<(basic_ostream<char, traits>&, const char16_t*) = delete; template<class traits> basic_ostream<char, traits>&operator<<(basic_ostream<char, traits>&, const char32_t*) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete; template<class traits> basic_ostream<wchar_t, traits>&operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete;}
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6060)
The class templatebasic_ostream defines a number of member function
signatures that assist in formatting and writing output to output sequences
controlled by a stream buffer[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6067)
Two groups of member function signatures share common properties:
the[*formatted output functions*](#def:formatted_output_functions) (or[*inserters*](#def:inserters))
and the[*unformatted output functions.*](#def:unformatted_output_functions.) Both groups of output functions generate (or[*insert*](#def:insert))
output[*characters*](#def:characters) by actions equivalent to callingrdbuf()->sputc(int_type)[.](#3.sentence-1)
They may use other public members ofbasic_ostream except that they shall not invoke any virtual members ofrdbuf() exceptoverflow(),xsputn(),
andsync()[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6091)
If one of these called functions throws an exception, then unless explicitly noted otherwise
the output function setsbadbit in the error state[.](#4.sentence-1)
Ifbadbit is set inexceptions(),
the output 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[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6105)
[*Note [1](#note-1)*:
The deleted overloads of operator<< prevent formatting characters as integers and strings as pointers[.](#5.sentence-1)
— *end note*]