A RetroSearch Logo

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

Search Query:

Showing content from http://en.cppreference.com/w/cpp/string/basic_string/../../io/ios_base/../basic_ostream/put.html below:

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

basic_ostream& put( char_type ch );

Behaves as an UnformattedOutputFunction. After constructing and checking the sentry object, writes the character ch to the output stream.

If the output fails for any reason, sets badbit.

[edit] Parameters [edit] Return value

*this

[edit] Notes

This function is not overloaded for the types signed char or unsigned char, unlike the formatted operator<<.

Unlike formatted output functions, this function does not set the failbit if the output fails.

[edit] Example
#include <fstream>
#include <iostream>
 
int main()
{
    std::cout.put('a'); // normal usage
    std::cout.put('\n');
 
    std::ofstream s("/does/not/exist/");
    s.clear(); // pretend the stream is good
    std::cout << "Unformatted output: ";
    s.put('c'); // this will set badbit, but not failbit
    std::cout << " fail=" << bool(s.rdstate() & s.failbit);
    std::cout << " bad=" << s.bad() << '\n';
    s.clear();
    std::cout << "Formatted output:   ";
    s << 'c'; // this will set badbit and failbit
    std::cout << " fail=" << bool(s.rdstate() & s.failbit);
    std::cout << " bad=" << s.bad() << '\n';
}

Output:

a
Unformatted output:  fail=0 bad=1
Formatted output:    fail=1 bad=1
[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