Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::cin,std::wcin

      From cppreference.com
      <cpp‎ |io
       
       
       
       
      Defined in header<iostream>
      externstd::istream cin;
      (1)
      externstd::wistream wcin;
      (2)

      The global objectsstd::cin andstd::wcin control input from a stream buffer of implementation-defined type (derived fromstd::streambuf), associated with the standard C input streamstdin.

      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).

      Unlesssync_with_stdio(false) has been issued, it is safe to concurrently access these objects from multiple threads for both formatted and unformatted input.

      Once initialized:

      1)std::cin.tie() returns&std::cout. This means that any input operation onstd::cin forces a call tostd::cout.flush() if any characters are pending for output..
      2)std::wcin.tie() returns&std::wcout. This means that any input operation onstd::wcin forces a call tostd::wcout.flush() if any characters are pending for output.

      [edit]Notes

      The “c” in the name refers to “character” (stroustrup.com FAQ);cin means “character input” andwcin means “wide character input”.

      [edit]Example

      Run this code
      #include <iostream> struct Foo{int n;    Foo(){std::cout<<"Enter n: ";// no flush needed        std::cin>> n;}}; Foo f;// static object int main(){std::cout<<"f.n is "<< f.n<<'\n';}

      Possible output:

      Enter n: 10f.n is 10

      [edit]See also

      initializes standard stream objects
      (public member class ofstd::ios_base)[edit]
      writes to the standard C output streamstdout
      (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/cin&oldid=181468"

      [8]ページ先頭

      ©2009-2025 Movatter.jp