SysTutorials Forums QA How to create a file if not exist and open it in read and write modes in C++?

How to create a file if not exist and open it in read and write modes in C++? For example, I would like open a fstream on /tmp/cache to be able to read it and append to it. If the file does not exist yet, create one.

A simple code like

std::fstream fs("/tmp/cache", std::ios::in | std::ios::out | std::ios::app);

will not create the file if it does not exist.

Reply To: How to create a file if not exist and open it in read and write modes in C++?
Your information:





<a href="" title="" rel="" target=""> <blockquote cite=""> <code> <pre> <em> <strong> <del datetime=""> <ul> <ol start=""> <li> <img src="" border="" alt="" height="" width="">

Please share if you like this post: