namespace std {
extern wistream wcin;
}
概要
wcin は、標準入力に対するワイド文字用の入力ストリームオブジェクトである。
すなわち、std::basic_streambufから派生していて<cstdio>のstdinオブジェクトに結びつけられているストリームバッファから入力を受ける。
本オブジェクトは、初期化が完了すると tie() が &wcout を返すようになる。
その他の状態は、basic_ios::init の事後条件と同様である。
wcinはwide character inputを意味する。[1]
例
#include <iostream>
#include <string>
int main()
{
std::wcout << L"名前を入力してください: ";
std::wstring s; // std::wcin.tie() == &std::wcout であるため、
std::wcin >> s; // std::wcout を明示的に flush しなくても
// 上記の出力が flush されることが保証されている
std::wcout << L"あなたの名前は「" << s << L"」ですね。" << std::endl;
}
出力例
名前を入力してください:たろう
あなたの名前は「たろう」ですね
バージョン
言語
- C++98
出典
- ^ Stroustrup: C++ Style and Technique FAQ(2018-08-21 17:01 JST 閲覧)