I want to output data to file that has a name of the current date on the computer. I used myInFile.open(date.c_str()) where date was set to the current system date. When I run the program it doesn't create the file. Is there something I'm doing wrong?
acording to my knowledg we us the bilt in functio c_str() if we will give the user an option
and that will help to convert the string into the c language
i usually do the following
[code] myInfile.open("name of the file.txt");/[code]
and if the file you want to open is in the note bad or somth you do the following
[code]muInfile.open("c;\\docoments\\data.txt");[code]
and this is gust an example but the hole bath of the file.
I am using the c_str() function but the file still isn't showing up in the directory. I'm using Visual Studio 2008 and the file never shows up in the directory.
Specifically what is the directory you are typing to save the file to? If you have a typo here the compiler might just assume it's a relative path and start making directories in your working folder, they are not perfect creatures.
I formed the time manually.
Example of what I did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%m-%d-%y %H:%M.txt",timeinfo); // NOTE: the ":" will not work, file name was "03-08-10 15" after output. Try using a different symbol, I'm going to use "+" in mine.
dateTime = buffer;
cout << "\n\n>>Saved to " << dateTime << endl;
/* Create File for later editing */
FILE * pFile;
pFile = fopen (dateTime.c_str(),"w");
fclose (pFile);
ofstream myfile;
myfile.open (dateTime.c_str());