How to check in C++ created the file?

Hello, is the code:
std::fstream file;
file.open(path.c_str(),std::ios::out);
file << "123";
file.close();

How to check whether the created file?
The General problem is: if possible,create a new file, if not, display the error message.
Thanks in advance!
August 23rd 19 at 10:50
4 answers
August 23rd 19 at 10:52
August 23rd 19 at 10:54
file.fail() check
file.fail() always returns me "0". For example: write in "C:\text.txt" the file is not created (because there is no access), but file.fail() gives "0" - antoinette18 commented on August 23rd 19 at 10:57
August 23rd 19 at 10:56
if (file.is_open()) {
...
}
file.is_open() always returns me "1". For example: write in "C:\text.txt" the file is not created (because there is no access), but file.is_open() gives "1" - antoinette18 commented on August 23rd 19 at 10:59
August 23rd 19 at 10:58
When the file is closed, it is necessary again to open and close (for reading). Here is the opening and it will become clear whether it appeared.

Find more questions by tags C++