std::basic_ostream::write(3)
β¨ std::basic_ostream::write(3) β¨
okay bestie, welcome to the std::basic_ostream::write(3) page from the C++ Standard Libary manual β yes, that's the manual name, and we're keeping it exactly as it appears. This one is all about that raw-character-output life. π
π NAME π
std::basic_ostream::write β and the name is literally std::basic_ostream::write. No mystery, no side quest. β¨
πΈ Synopsis πΈ
basic_ostream& write( const char_type* s, std::streamsize count );
Behaves as an UnformattedOutputFunction. After constructing and checking the sentry object, it outputs the characters from successive locations in the character array whose first element is pointed to by s. Characters are inserted into the output sequence until one of these things happens:
- exactly
countcharacters are inserted - inserting into the output sequence fails β in which case
setstate(badbit)is called. π
π«Ά Parameters π«Ά
sβ pointer to the character string to writecountβ number of characters to write
β Return value β
*this
π₯ Exceptions π₯
failureif an error occurred (the error state flag is notgoodbit) andexceptions()is set to throw for that state.- If an internal operation throws an exception, it is caught and
badbitis set. Ifexceptions()is set forbadbit, the exception is rethrown.
π Notes π
- This function is not overloaded for the types
signed charorunsigned char, unlike the formattedoperator<<. - Also, unlike the formatted output functions, this function does not set the
failbiton failure. - When using a non-converting locale (the default locale is non-converting), the overrider of this function in
std::basic_ofstreammay be optimized for zero-copy bulk I/O (by means of overridingstd::streambuf::xsputn).
π¦ Example π¦
This function may be used to output object representations, i.e. binary output.
// Run this code
#include <iostream>
int main()
{
int n = 0x41424344;
std::cout.write(reinterpret_cast<char*>(&n), sizeof n) << '\n';
char c[] = "This is sample text.";
std::cout.write(c, 4).write("!\n", 2);
}
π Possible output π
DCBA
This!
π See also π
operator<<(std::basic_ostream)β inserts character data or insert into rvalue stream (function template)putβ inserts a character (public member function)
okay that's the whole page, bestie β no details left behind. source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::basic_ostream::write(3) πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms