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.
如果不存在,如何创建文件并在C ++中以读写模式打开文件? 例如,我想在/tmp/ cache
上打开fstream以便能够读取并追加到它。 如果该文件尚不存在,请创建一个。
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.
如果文件不存在,则不会创建该文件。
When fstream is constructed with std::ios::in
included, if the file does not exist, the std::ios::in
portion f