Hi I want to increment file number with date e.g 19-FEB-09-1.dat, 19-FEB-09-2.dat .... So in the write function after it runs for certain number of times say 12 the file number then increments to next one. However, if the file number already exists it then move to next number to write to file. Ignore the file read command in my code.
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <time.h>
#include <conio.h>
using namespace std;
void WriteToFile(const char *filename, int ArraySize);
int _tmain(int argc, _TCHAR* argv[])
{
static const char filename[] = "data.dat";
int ArraySize=10;
WriteToFile(filename, ArraySize);
return 0;
}
void WriteToFile(const char *filename, int ArraySize)
{
double *read_dist=new double[ArraySize];
double *read_ampl=new double[ArraySize];
int i;
double c[10]={1.23578,2,3,4,5,6,7,8,9,10};
double d[10]={5,6,7,8,9,4,3,2,3,4};
double *dist=c;
double *ampl=d;
//while( !_kbhit() )
//{
//FILE NUMBER INCREMENT
std::ofstream fileout(filename,ios::out | ios::binary );
if(!fileout)
{
std::cout << "Cannot open file to write.\n";
}
for(int n=0;n<12;n++)
{
fileout.write((char *) dist, sizeof(double)*ArraySize);
fileout.write((char *) ampl, sizeof(double)*ArraySize);
}
fileout.close();
//}
}