A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../ranges/../../cpp/io/basic_ostream/operator_ltlt.html below:

std::basic_ostream<CharT,Traits>::operator<< - cppreference.com

basic_ostream& operator<<( bool value );

(1)

basic_ostream& operator<<( long value );

(2)

basic_ostream& operator<<( unsigned long value );

(3)

basic_ostream& operator<<( long long value );

(4) (since C++11)

basic_ostream& operator<<( unsigned long long value );

(5) (since C++11)

basic_ostream& operator<<( double value );

(6)

basic_ostream& operator<<( long double value );

(7)

basic_ostream& operator<<( const void* value );

(8)

basic_ostream& operator<<( const volatile void* value );

(9) (since C++23) (10) (since C++17)

basic_ostream& operator<<( short value );

(11)

basic_ostream& operator<<( int value );

(12)

basic_ostream& operator<<( unsigned short value );

(13)

basic_ostream& operator<<( unsigned int value );

(14)

basic_ostream& operator<<( float value );

(15)

basic_ostream& operator<<( /* extended-floating-point-type */ value );

(16) (since C++23) (17) (18) (19) (20)

Inserts data into the stream.

1-8) Inserts value.

This function behaves as a

FormattedOutputFunction

. After constructing and checking the sentry object, inserts a value by calling

std::num_put::put()

. If the end of file condition was encountered during output (

put().failed() == true

), sets

badbit

.

9) Equivalent to return operator<<(const_cast<const void*>(p));.

10) Equivalent to return *this << s;, where s is an implementation-defined null-terminated character type string.

11) Inserts a value from short value.

12) Inserts a value from int value.

13,14) Inserts a value from unsigned short or unsigned int value.

This function behaves as a

FormattedOutputFunction

. After constructing and checking the sentry object, inserts

static_cast<unsigned long>(value)

as in

(3)

.

15) Inserts a value from float value.

This function behaves as a

FormattedOutputFunction

. After constructing and checking the sentry object, inserts

static_cast<double>(value)

as in

(6)

.

16)

Inserts a value from

value

. The library provides overloads for all cv-unqualified

extended floating-point types

as the type of the parameter value.

This function behaves as a

FormattedOutputFunction

. After constructing and checking the sentry object, checks the

floating-point conversion rank

of

/* extended-floating-point-type */

:

17)

This function behaves as an

UnformattedOutputFunction

. After constructing and checking 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:

If no characters were inserted, executes

setstate(failbit)

. If an exception was thrown while extracting, sets

failbit

and, if

failbit

is set in

exceptions()

, rethrows the exception.

18-20)

Calls

func(*this)

. These overloads are used to implement output I/O manipulators such as

std::endl

.

[edit] Parameters value - integer, floating-point, boolean, or pointer value to insert func - function to call sb - pointer to the stream buffer to read the data from [edit] Return value

1-19) *this

20) func(*this)

[edit] Notes

There are no overloads for pointers to non-static members, pointers to volatiles,(until C++23) or function pointers (other than the ones with signatures accepted by the (18-20) overloads).

Character and character string arguments (e.g., of type char or const char*) are handled by the non-member overloads of operator<<.

Overload (10) was added by the resolution of LWG issue 2221, but it is never implemented in any standard library implementation under C++11/14 modes.

[edit] Example
#include <iomanip>
#include <iostream>
#include <sstream>
 
int fun() { return 42; }
 
int main()
{
    std::istringstream input(" \"Some text.\" ");
    double f = 3.14;
    bool b = true;
 
    std::cout
        << fun()          // int overload (12)
        << ' '            // non-member overload
        << std::boolalpha // function overload (18)
        << b              // bool overload (1)
        << " "            // non-member overload
        << std::fixed     // function overload (18) again
        << f              // double overload (6)
        << input.rdbuf()  // streambuf overload
        << fun            // bool overload (1): there's no overload for int(*)()
        << std::endl;     // function overload (18) again
 
    int x = 0;
    int* p1 = &x;
    volatile int* p2 = &x;
    std::cout
        << "p1: " << p1 << '\n'  // `const void*` overload, prints address
        << "p2: " << p2 << '\n'; // before C++23 (P1147): bool overload :), because
            // operator<<(const void*) is not a match, as it discards the `volatile`
            // qualifier. To fix this, C++23 adds `const volatile void*` overload (9),
            // that prints the address as expected.
}

Possible output:

42 true 3.140000 "Some text." true
p1: 0x7ffcea766600
p2: 0x7ffcea766600
[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4