Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_ostream<CharT,Traits>::write

      From cppreference.com
      <cpp‎ |io‎ |basic ostream
       
       
       
       
      basic_ostream& write(const char_type* s,std::streamsize count);

      Behaves as anUnformattedOutputFunction. After constructing and checking the sentry object, outputs the characters from successive locations in the character array whose first element is pointed to bys. Characters are inserted into the output sequence until one of the following occurs:

      • exactlycount characters are inserted
      • inserting into the output sequence fails (in which casesetstate(badbit) is called).

      Contents

      [edit]Parameters

      s - pointer to the character string to write
      count - number of characters to write

      [edit]Return value

      *this

      [edit]Exceptions

      [edit]
      failure if 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 andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.

      [edit]Notes

      This function is not overloaded for the typessignedchar orunsignedchar, unlike the formattedoperator<<.

      Also, unlike the formatted output functions, this function does not set thefailbit on failure.

      When using a non-converting locale (the default locale is non-converting), the overrider of this function instd::basic_ofstream may be optimized for zero-copy bulk I/O (by means of overridingstd::streambuf::xsputn).

      [edit]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:

      DCBAThis!

      [edit]See also

      inserts character data or insert into rvalue stream
      (function template)[edit]
      inserts a character
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ostream/write&oldid=154113"

      [8]ページ先頭

      ©2009-2025 Movatter.jp