create a file if not exist in c++ in ofstream code example Example: c++ fstream create if not exists file.open("test.txt",fstream::out);