第八章
程序员文章站
2022-07-12 17:59:06
...
#include<iostream>
using namespace std;
int main()
{
wchar_t w_ch;
wcin.imbue(locale("chs"));
wcout.imbue(locale("chs"));
//设置语言环境
wcin >> w_ch;
wcout << w_ch << flush;
}
//io流对于unicode字符设计了wchar_t类型
//所以为什么不能用string
io对象无拷贝或者赋值,因此流不可能被设置为形参或返回类型。读写一个Io对象会改变流的状态,因而流不会是const的
int main()
{
//io流设置了四个状态位,good代表流是否有效,bad代表是否崩溃,fail代表是否有一个io操作失败,end表示是否流到达了文件结束。一个流一旦在某个地方发生错误,我们就不能用它读写数据。
cout << "before read" << endl;
if (cin.good()) cout << "cin's good" << endl;
if (cin.bad()) cout << "cin's bad" << endl;
if (cin.fail()) cout << "cin's fail" << endl;
if (cin.eof()) cout << "cin's eof" << endl;
read();
cout << "after read" << endl;
if (cin.good()) cout << "cin's good" << endl;
if (cin.bad()) cout << "cin's bad" << endl;
if (cin.fail()) cout << "cin's fail" << endl;
if (cin.eof()) cout << "cin's eof" << endl;
off();
cout << "after off" << endl;
if (cin.good()) cout << "cin's good" << endl;
if (cin.bad()) cout << "cin's bad" << endl;
if (cin.fail()) cout << "cin's fail" << endl;
if (cin.eof()) cout << "cin's eof" << endl;
return 0;
}