您的位置:首页 > 其它

IO对象的相关属性与操作

2018-03-03 14:40 155 查看

IO对象的相关属性与操作

#include "stdafx.h"
#include <iostream>
using namespace std;

#include <fstream>

//IO 对象不可复制或赋值

//void func(fstream fs)
//{
//
//}

void func(fstream& fs)
{

}

int _tmain(int argc, _TCHAR* argv[])
{
fstream f1, f2;

//f1=f2; 不可赋值
//fstream f3(f2); 不可复制

//func(f2); 不可复制(调用拷贝构造)
func(f1); //传引用不调用拷贝构造

#if 0
刷缓冲

setvbuf(stdout, NULL, _IOFBF, 1024); //此函数还原linux系统部分环境

cout << "sfgsfsfgsgfss----" << flush;
//如果不加flush的话不会刷缓冲 黑窗口不会显示数据
//加endl会刷缓冲 但是会引入\n使之换行
cout << unitbuf << "sdfsfsfsfsfsfs"; //设置一次unitbuf以后都刷新
cout << "=========";
while (1);

#endif

fstream fs("xx.txt", ios::in | ios::out | ios::trunc);
if (!fs)
cout << "open error" << endl;
fs << 12 << " " << 23 << " " << 24 << endl;

fs.seekg(0, ios::beg); //将指针指向头

int a, b, c;

fs >> a >> b >> c;

cout << a << endl;
cout << b << endl;
cout << c << endl;

fs.close();

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: