Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::cout,std::wcout

      From cppreference.com
      <cpp‎ |io
       
       
       
       
      Defined in header<iostream>
      externstd::ostream cout;
      (1)
      externstd::wostream wcout;
      (2)

      The global objectsstd::cout andstd::wcout control output to a stream buffer of implementation-defined type (derived fromstd::streambuf), associated with the standard C output streamstdout.

      These objects are guaranteed to be initialized during or before the first time an object of typestd::ios_base::Init is constructed and are available for use in the constructors and destructors of static objects withordered initialization (as long as<iostream> is included before the object is defined).

      Unlessstd::ios_base::sync_with_stdio(false) has been issued, it is safe to concurrently access these objects from multiple threads for both formatted and unformatted output.

      By specification ofstd::cin,std::cin.tie() returns&std::cout. This means that any input operation onstd::cin executesstd::cout.flush() (viastd::basic_istream::sentry's constructor). Similarly,std::wcin.tie() returns&std::wcout.

      By specification ofstd::cerr,std::cerr.tie() returns&std::cout. This means that any output operation onstd::cerr executesstd::cout.flush() (viastd::basic_ostream::sentry's constructor). Similarly,std::wcerr.tie() returns&std::wcout.(since C++11)

      Notes

      The 'c' in the name refers to "character" (stroustrup.com FAQ);cout means "character output" andwcout means "wide character output".

      Becausedynamic initialization oftemplated variables are unordered, it is not guaranteed thatstd::cout has been initialized to a usable state before the initialization of such variables begins, unless an object of typestd::ios_base::Init has been constructed.

      Example

      Run this code
      #include <iostream> struct Foo{int n;    Foo(){        std::cout<<"static constructor\n";}    ~Foo(){        std::cout<<"static destructor\n";}}; Foo f;// static object int main(){    std::cout<<"main function\n";}

      Output:

      static constructormain functionstatic destructor

      See also

      initializes standard stream objects
      (public member class ofstd::ios_base)[edit]
      writes to the standard C error streamstderr, unbuffered
      (global object)[edit]
      writes to the standard C error streamstderr
      (global object)[edit]
      expression of typeFILE* associated with the input stream
      expression of typeFILE* associated with the output stream
      expression of typeFILE* associated with the error output stream
      (macro constant)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/cout&oldid=181465"

      [8]ページ先頭

      ©2009-2025 Movatter.jp