std::cin, std::wcin
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <iostream> 中定义
|
||
extern std::istream cin; |
(1) | |
extern std::wistream wcin; |
(2) | |
全球的对象std::cin,std::wcin控制输入流缓冲的实现定义类型(来自std::streambuf),与标准的C输入流stdin.
原文:
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.
保证这些对象被称为以前建造的第一个构造函数中的静态对象,保证他们活得比最后的静态对象的析构函数,所以它总是能够在用户代码中读取std::cin.
原文:
These objects are guaranteed to be constructed before the first constructor of a static object is called and they are guaranteed to outlive the last destructor of a static object, so that it is always possible to read from std::cin in user code.
除非sync_with_stdio(false)已经发出,它是安全的格式化和未格式化的输入为从多个线程同时访问这些对象.
原文:
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.
一旦std::cin构造,std::cin.tie()回报&std::cout,同样地,std::wcin.tie()回报&std::wcout。这意味着,任何格式的输入操作std::cin强制调用std::cout.flush()如果任何字符待输出,.
原文:
Once std::cin is constructed, std::cin.tie() returns &std::cout, and likewise, std::wcin.tie() returns &std::wcout. This means that any formatted input operation on std::cin forces a call to std::cout.flush() if any characters are pending for output.
[编辑] 示例
输出:
Enter n: 10 f.n is 10
[编辑] 另请参阅
标准流对象进行初始化 原文: initializes standard stream objects (公共成员类of std::ios_base )
| |
写入标准C的输出流stdout
(全局对象)的 原文: writes to the standard C output stream stdout (全局对象) |