需要文件 io 的 c++ 跨平台方法

标签 c++ file file-io cross-platform

在c/c++中是否有任何标准的文件-io的跨平台模拟

   int open(const char *pathname, int flags, mode_t mode);

?

最佳答案

int open(const char *pathname, int flags, mode_t mode) 不是 C++。它是纯 C。

你应该使用 std::fstream ( http://www.cplusplus.com/reference/fstream/fstream/ )

#include <fstream>     

int main () {

  std::fstream fs;
  fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);

  fs << " more lorem ipsum";

  fs.close();

  return 0;
}

关于需要文件 io 的 c++ 跨平台方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18462270/

相关文章:

java - 如何等待 HTTP 请求在 Java 中完成

c - C语言中如何求一个数的长度?

matlab - 我可以使用并行计算读取一个巨大的文本文件吗?

c++ - "File could not be opened."C++ fstream

c++ - MPI 使用 MPI_Alltoallv 发送动态大小的数组

c++ - 使用单个指针访问连续成员

c++ - 如何在 LLDB 中编辑命令行?

c++ - 休眠功能但不阻止其他功能和代码

javascript - 在不丢失数据或压缩的情况下将 blob 转换为 WAV 文件

c++ - 在 C++ 中使用 ifstream 逐行读取文件