Home > Back-end >  After c ofstream to determine whether a file exists, create success, to failure
After c ofstream to determine whether a file exists, create success, to failure

Time:04-09

# include "stdafx. H"
#include
#include
#include
#include
#include


using namespace std;

Int _tmain (int arg c, _TCHAR * argv [])
{
Ofstream outFile;
OutFile. Open (" D: \ \ myfile CSV ", the ios: : in);
if(! OutFile) {
OutFile. Open (" D: \ \ myfile CSV ", the ios: : out);
OutFile & lt; <"Name" & lt; <", "& lt; <"Age" & lt; <", "& lt; <"Height" & lt; OutFile. Close ();
}
The else {
OutFile. Close ();
OutFile. Open (" D: \ \ myfile CSV ", the ios: : out | ios: : ate | ios: : app);
OutFile & lt; <"Tom" & lt; <", "& lt; <21 & lt; <", "& lt; <172.8 & lt; OutFile & lt; <"John" & lt; <", "& lt; <25 & lt; <", "& lt; <189.5 & lt; OutFile. Close ();
}
return 0;
}
File does not exist, if performs, file creation is successful, but I can't write data

, help to see where the problem, thank you
  • Related