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();
 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-09-09
  • 2021-11-30
  • 2022-01-24
  • 2021-12-10
猜你喜欢
  • 2021-07-20
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案