Пространства имён
Варианты
Действия

std::basic_ostream::operator<<

Материал из cppreference.com

 
 
Библиотеки ввода / вывода
I / O манипуляторов
C-стиль I / O
Буферы
Original:
Buffers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_streambuf
basic_filebuf
basic_stringbuf
strstreambuf(устарело)
Потоки
Original:
Streams
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Абстракций
Original:
Abstractions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ios_base
basic_ios
basic_istream
basic_ostream
basic_iostream
Файл I / O
Original:
File I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ifstream
basic_ofstream
basic_fstream
Струнный I / O
Original:
String I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_istringstream
basic_ostringstream
basic_stringstream
Массив I / O
Original:
Array I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
istrstream(устарело)
ostrstream(устарело)
strstream(устарело)
Типы
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
streamoff
streamsize
fpos
Интерфейс Ошибка категории
Original:
Error category interface
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iostream_category(C++11)
io_errc(C++11)
 
std::basic_ostream
Глобальные объекты
Original:
Global objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Член функций
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::basic_ostream
basic_ostream::~basic_ostream
basic_ostream::operator=(C++11)
Форматированный ввод
Original:
Formatted input
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::operator<<
Неформатированная вход
Original:
Unformatted input
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::put
basic_ostream::write
Позиционирование
Original:
Positioning
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::tellp
basic_ostream::seekp
Разное
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::flush
basic_ostream::swap(C++11)
Член классов
Original:
Member classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ostream::sentry
Не являющиеся членами функций
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator<<(std::basic_ostream)
 
basic_ostream& operator<<( short value );
basic_ostream& operator<<( unsigned short value );
(1)
basic_ostream& operator<<( int value );
basic_ostream& operator<<( unsigned int value );
(2)
basic_ostream& operator<<( long value );
basic_ostream& operator<<( unsigned long value );
(3)
basic_ostream& operator<<( long long value );
basic_ostream& operator<<( unsigned long long value );
(4) (начиная с C++11)
basic_ostream& operator<<( float value );

basic_ostream& operator<<( double value );

basic_ostream& operator<<( long double value );
(5)
basic_ostream& operator<<( bool value );
(6)
basic_ostream& operator<<( const void* value );
(7)
basic_ostream& operator<<( std::basic_streambuf<CharT, Traits>* sb);
(8)
basic_ostream& operator<<( basic_ostream& st,

                           std::ios_base& (*func)(std::ios_base&) );
basic_ostream& operator<<( basic_ostream& st,
                           std::basic_ios<CharT,Traits>& (*func)(std::basic_ios<CharT,Traits>&) );
basic_ostream& operator<<( basic_ostream& st,

                           std::basic_ostream& (*func)(std::basic_ostream&) );
(9)
Вставка данных в поток.
Original:
Inserts data into the stream.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(1-7) версии оператора ведут себя, как отформатированные функции вывода и 8) версия ведет себя как неформатированный выходной функции. Эти функции начинается выполнение путем построения объекта типа sentry, который очищает tie()'d выходные буферы при необходимости и проверяет поток ошибок. После завершения строительных работ, если часовой объект возвращается false, функции возвращают не пытаясь никаких выходных данных. Если ошибка появляется во время выходных, отформатированных выходных функций установлены setstate(ios_base::failbit). Если исключение во время выходных, то IOS :: badbit установлен (за исключением подавляется, если (exceptions()&badbit) != 0, в этом случае он выдается повторно)
Original:
The (1-7) versions of the operator behave as formatted output functions, and the 8) version behaves as unformatted output function. These functions begin execution by constructing an object of type sentry, which flushes the tie()'d output buffers if necessary and checks the stream errors. After construction, if the sentry object returns false, the functions return without attempting any output. If an error occurs during output, formatted output functions set setstate(ios_base::failbit). If an exception is thrown during output, then ios::badbit is set (the exception is suppressed unless (exceptions()&badbit) != 0, in which case it is rethrown)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1-2)
Если value является short или int, затем бросает его в unsigned short или unsigned int если ios_base::flags() & ios_base::basefield является ios_base::oct или ios_base::hex. После этого бросает в long в любом случае и выходов, а в 3). Если value является unsigned short или unsigned int, бросает в unsigned long и выходов, а в 3)
Original:
If value is short or int, then casts it to unsigned short or unsigned int if ios_base::flags() & ios_base::basefield is ios_base::oct or ios_base::hex. After that, casts to long in any case and outputs as in 3). If value is unsigned short or unsigned int, casts to unsigned long and outputs as in 3)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-4)
Вставки целое значение, вызвав num_put::put(). Если конец файла условием была обнаружена во время выхода (put().failed() == true), устанавливает ios::badbit.
Original:
Inserts an integer value by calling num_put::put(). If the end of file condition was encountered during output (put().failed() == true), sets ios::badbit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
Вставляет значение с плавающей точкой, вызвав num_put::put() Если конец файла условием была обнаружена во время выхода (put().failed() == true), устанавливает ios::badbit.
Original:
Inserts a floating point value by calling num_put::put() If the end of file condition was encountered during output (put().failed() == true), sets ios::badbit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
Вставки bool значения по телефону num_put::put() Если конец файла условием была обнаружена во время выхода (put().failed() == true), устанавливает ios::badbit.
Original:
Inserts bool value by calling num_put::put() If the end of file condition was encountered during output (put().failed() == true), sets ios::badbit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
Вставляет общее значение указателя по телефону num_put::put() Если конец файла условием была обнаружена во время выхода (put().failed() == true), устанавливает ios::badbit.
Original:
Inserts a generic pointer value by calling num_put::put() If the end of file condition was encountered during output (put().failed() == true), sets ios::badbit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
Вставки все данные из sb. После построения часового объект, проверяет sb является нулевым указателем. Если это так, выполняет setstate(badbit) и выходы. В противном случае, извлекает символы из входной последовательности контролируется sb и вставляет их в *this до одного из следующих условий:
Original:
Inserts all data from sb. After constructing the sentry object, checks if sb is a null pointer. If it is, executes setstate(badbit) and exits. Otherwise, extracts characters from the input sequence controlled by sb and inserts them into *this until one of the following conditions are met:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • конец файла происходит на входной последовательности;
    Original:
    end-of-file occurs on the input sequence;
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • вставка в выходной последовательности не удается (в этом случае символ, который будет вставлен не извлекается);
    Original:
    inserting in the output sequence fails (in which case the character to be inserted is not extracted);
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • происходит исключение (в этом случае исключение перехватывается).
    Original:
    an exception occurs (in which case the exception is caught).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Если символы не были добавлены, выполняет setstate(badbit). Если исключение при добыче, устанавливает failbit
Original:
If no characters were inserted, executes setstate(badbit). If an exception was thrown while extracting, sets failbit
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
9)
Звонки func(*this);. Эта перегрузка используется для реализации выхода I / O манипуляторы, такие как std::endl.
Original:
Calls func(*this);. This overload is used to implement output I/O manipulators such as std::endl.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

value -
целое, с плавающей точкой, логические, или значение указателя для вставки
Original:
integer, floating-point, boolean, or pointer value to insert
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
func -
функции для вызова
Original:
function to call
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sb -
указатель на streambuffer читать данные
Original:
pointer to the streambuffer to read the data from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Возвращаемое значение

*this

[править] Notes

Есть нет перегрузки для указателей на летучих или указателей на функции (кроме тех, с подписями принято 9) перегрузки). Попытка вывода таких объектов вызывает неявное преобразование в bool, и для любой ненулевой указатель, значение 1 печатается (если boolalpha был установлен).
Original:
There are no overload for pointers to volatile or function pointers (other than the ones with signatures accepted by the 9) overload). Attempting to output such objects invokes implicit conversion to bool, and, for any non-null pointer value, the value 1 is printed (unless boolalpha was set).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

#include <iostream>
#include <iomanip>
#include <sstream>
int main()
{
    std::istringstream input(" \"Some text.\" ");
    volatile int n = 42;
    double f = 3.14;
    bool b = true;;
    std::cout << n   // int overload
              << ' ' // non-member overload
              << std::boolalpha << b // bool overload
              << " " // non-member overload
              << std::fixed << f // double overload
              << input.rdbuf() // streambuf overload
              << &n // bool overload
              << std::endl; // function overload
}

Вывод:

42 true 3.140000 "Some text." true

[править] См. также

вставками символьных данных
Original:
inserts character data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
выполняет поток ввода / вывода строк
Original:
performs stream I/O of strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(шаблон функции)
выполняет входной поток и выход bitsets
Original:
performs stream input and output of bitsets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция)
сериализации и десериализации комплексного числа
Original:
serializes and deserializes a complex number
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(шаблон функции)
осуществляет входной поток и выход на псевдослучайных чисел двигателя
Original:
performs stream input and output on pseudo-random number engine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
осуществляет входной поток и выход на псевдослучайных чисел распределения
Original:
performs stream input and output on pseudo-random number distribution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
вставками характер
Original:
inserts a character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(public функция-член) [edit]
вставки блоков символов
Original:
inserts blocks of characters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(public функция-член) [edit]