c++ 中最简单的文件读写

180it 2020-03-06 AM 1743℃ 0条
#include <fstream>
#include <iostream>
#include <string>
 
void write() {
  std::fstream file("file.txt",
                    std::fstream::in | std::fstream::out | std::fstream::app);
  file << "aaalin";
  file.close();
}
 
void read() {
  std::string str;
  std::fstream file("file.txt", std::fstream::in);
  file >> str;
  std::cout << str;
  file.close();
}
 
int main() {
  write();  // 向file.txt文件写入内容
  read();  // 读取file.txt文件内容
  return 0;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

c++ 中最简单的文件读写