码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 读写文件流

时间:2015-06-11 22:54:12      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

1. 读文件流 

string readpro(const char* path) {

  ifstream infile(path);
  char buf[1024];
  string message = "";

  // 假如 infile 后面没有路径,要先打开文件 infile.open(path);

  if (infile.is_open()) {
    while (infile.good() && !infile.eof()) {
      memset(buf, 0, 1024);
      infile.getline(buf, 1024);
      message += buf;
    }
    infile.close();
  } else
    cout << "error!" << endl;
  return message;
}

 

2. 写文件流:

ofstream outfile("/data/name.out", ios::trunc);
outfile.write((char*)result.string(), result.length());
outfile.close();
 

 

C++ 读写文件流

标签:

原文地址:http://www.cnblogs.com/wxmdevelop/p/4570163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!