When i open file by the next way: ofstream outputFile(Filename, ios::out | ios::binary);
i gets error result when the dire开发者_如何转开发ctory not exist:
temp\filename.ext
when the directory exist it work well. I want to know how can i force the operation in c++ command
You can't. There is no standardized way to create a directory in c++.
You might want to take a look at the filesystem library from boost. There are multiple functions for checking if the directory/file exits and if not how to create them.
The file is created automatically when creating an ofstream
if it does not exist. But the directory where you want this file to be created must already exist.
There is no way to create a directory automatically in C++. You have to create the directory in C++.
Furthermore, and unfortunately, there's no C++ standard way of dealing with directories. You'll have to revert to the C system library mkdir
of your operating system to create it.
I'm the first to admit I know nothing about C, but in any programming language trying to force an open file operation on a file that doesn't exist is a BAD THING!
Check if the file you're trying to open exists. If it doesn't, create it. If you can't create it, then fail gracefully.
精彩评论