1

I am relatively new to using the boost library for c++ and I am wondering how to open a file using this. My aim is to read from a json file however I do not know how to open the file.

In c++, you can do this

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

but how can I do this using boost?

Lemons
  • 176
  • 1
  • 18
  • Perhaps the SO item [Serializing and deserializing json with boost](http://stackoverflow.com/questions/12394472/serializing-and-deserializing-json-with-boost) will help. – R Sahu Apr 19 '14 at 21:07
  • 2
    using boost will not add much here. – shoosh Apr 19 '14 at 21:09
  • Boost is just a library. It adds things that the standard library _doesn't_ have. This is **not** an example of such a thing. – sehe Apr 19 '14 at 22:09

1 Answers1

3

You can use boost::filesystem::ifstream (which works with a boost::filesystem::path instance) or simply use a std::ifstream to read the file.

The actual code depends a lot on your concrete use-case.

Manthan Tilva
  • 3,135
  • 2
  • 17
  • 41
utnapistim
  • 26,809
  • 3
  • 46
  • 82