std::cin, std::wcin
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
cinwcin | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted input | ||||
| Unformatted input | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
| Defined in header <iostream>
|
||
| extern std::istream cin; |
(1) | |
| extern std::wistream wcin; |
(2) | |
The global objects std::cin and std::wcin control input from a stream buffer of implementation-defined type (derived from std::streambuf), associated with the standard C input stream stdin.
These objects are guaranteed to be initialized during or before the first time an object of type std::ios_base::Init is constructed and are available for use in the constructors and destructors of static objects with ordered initialization (as long as <iostream> is included before the object is defined).
Unless sync_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:
std::cin forces a call to std::cout.flush() if any characters are pending for output..std::wcin forces a call to std::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” and wcin means “wide character input”.
[edit] Example
Possible output:
Enter n: 10 f.n is 10
[edit] See also
| initializes standard stream objects (public member class of std::ios_base) [edit]
| |
| writes to the standard C output stream stdout (global object)[edit] | |
| expression of type FILE* associated with the input stream expression of type FILE* associated with the output stream expression of type FILE* associated with the error output stream (macro constant) [edit] |