//********************输入输出字符串流测试*************************intmain(){//输入字符串流
istringstream s("47 1.414 this is a test");//如果把47变成4.7 i 就会等于4 f 等于0.7int i;double f;
string c;
s >> i;
s >> f;
s >> c;
cout << i<<endl;
cout << f << endl;
cout << c << endl;
cout << s.rdbuf()<< endl;//输出字符串流
cout <<"type an int ,a float and a string";
cin >> i;
cin >> f;
cin >> std::ws;//输入一个空格符
string strBuff;
std::getline(cin, strBuff);
ostringstream os;
os <<"interger = "<< i << endl;
os <<"float = "<< f << endl;
os <<"string = "<< strBuff << endl;
string result = os.str();
cout <<"result : "<< result << endl;}
输入输出流的格式化
//********************* 输入输出流的格式化 ***********************intmain(){
ofstream out("out.txt");
out.setf(std::ios::unitbuf);//一个标志位,每次out中加入数据,都会刷新流将文件写到 out中,所以即使abort了,文件还是会被写入
out.setf(std::ios::showpos);//符号标志位,遇到数字显示+号
out.unsetf(std::ios::showpos);//取消显示+号
out <<" one ";
out <<" two ";
out <<3;//abort();}