#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ostream hexout(cout.rdbuf());
hexout.setf(ios::hex, ios::basefield);
hexout.setf(ios::showbase);
hexout << "hexout: " << 177 << " ";
//cout << "cout: " <<177 << " ";
//hexout << endl;
cout << endl;
istream hexin(cin.rdbuf());
hexin.setf(ios::hex, ios::basefield);
hexin.setf(ios::showbase);
int x;
hexin >>x;
cout << x <<endl;
return 0;
}
hexout: 0xb1
F
15
当向一个输出流写入数据的时候,数据会先执行输出流所定义的格式化操作,之后才会写入其对应的缓冲区中.
当一个输入流读入数据的时候,数据会先写入缓冲区中,之后将缓冲区中的数据读出执行其输入流对应的格式化操作.