c++ cross-platform method for file-io is needed

Is there any standard cross-platform analogue for file-io in c/c++ to

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

?

Upvotes: 2

Views: 4260

Answers (2)

zoska
zoska

Reputation: 1723

File descriptors aren't cross platform, they belong to POSIX standard, so they will work on Linux/Unix-like systems only.

Upvotes: 3

Alex
Alex

Reputation: 91

int open(const char *pathname, int flags, mode_t mode) is not C++. It is pure C.

You should use 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;
}

Upvotes: 8

Related Questions