需要c ++跨平台的file-io方法

Շու*_*յան 1 c++ file-io cross-platform file

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

   int open(const char *pathname, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)

小智 7

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;
}
Run Code Online (Sandbox Code Playgroud)