Here this is a program i wrote where i put part of the date in
the file name, this code also show you how you can change the
date.
Code:
#include <iostream>
#include <fstream>
#include <time.h>
#include <string>
#include <vector>
#include <process.h>
using namespace std;
int main()
{
struct tm when;
__time64_t now;
_time64( &now );
when = *_localtime64( &now );
vector<string> vDate;
char * date;
date = asctime( &when );
string sDate;
string sDate3;
sDate = date;
sDate3.insert(0, sDate, 0, 10);
sDate3 += ".txt";
fstream file;
file.open(sDate3.c_str(), ios::in);
if(!file.fail())
{
sDate3.insert(0, "type \"");
sDate3.insert(20, "\"");
system(sDate3.c_str());
cout << endl << endl;
cout << "Press any key to Continue!" << endl;
cin.get();
}
char * date2;
string sDate2;
string sDate4;
string sInfo;
int quanity;
bool EXIT = false;
while(EXIT == false)
{
cout << "Enter Customer Info : " << endl;
getline(cin, sInfo, '\n');
cout << "Enter Quanity : ";
cin >> quanity;
quanity -= 20;
if(sInfo[0] == '\0')
{
EXIT = true;
}
else
{
cin.ignore();
if(quanity < 0)
{
cout << "Quanity Must be more then 20" << endl;
cout << "Re enter the amount : ";
cin >> quanity;
cin.ignore();
}
for(int i = 0; i != 3; i++)
{
when.tm_mday = when.tm_mday + quanity;
_mktime64( &when );
date2 = asctime( &when );
sDate2 = date2;
sDate4.insert(0, sDate2, 0, 10);
vDate.push_back(sDate4);
sDate4 += ".txt";
fstream file1;
file1.open(sDate4.c_str(), ios::app | ios::out);
if(i == 0)
{
file1 << sInfo << endl;
}
else
{
file1 << endl << "*** ORIGINAL REMIND DATE " << vDate[0] << " ***" << endl;
file1 << sInfo << endl << endl;
}
file1.close();
sDate2.clear();
sDate4.clear();
}
}
}
return 0;
}