S
skywalker skywalker
Hi Guru,
I got following code, but the problem is it only generates one file.
I would want it to generate 5 files (filename in format
"sample_<number>_<timestamp>" , with each file contains 10 entries of
the text "This is sample".
What is wrong with the code ? I couldn't figure it out..
#include <fstream>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>
using namespace std;
void main (void)
{
std::stringstream stream;
struct tm *ptr;
time_t tm;
char timestamp[60];
string xstr = "This is sample";
for( int n = 1; n <= 5; ++n)
{
tm = time(NULL);
ptr = localtime(&tm);
memset(timestamp,0,sizeof(timestamp));
strftime(timestamp ,100 , "%Y%m%d_%H%M%S",ptr);
stream << "C:\\output\\sample_" << n << "_" << timestamp <<
".txt" ;
std:fstream SaveFile(stream.str().c_str());
for( int j = 1; j <= 10; ++j)
{
SaveFile << xstr << endl;
}
SaveFile.close();
}
}
Thanks. appreciate your kind advise.
Skywalker
I got following code, but the problem is it only generates one file.
I would want it to generate 5 files (filename in format
"sample_<number>_<timestamp>" , with each file contains 10 entries of
the text "This is sample".
What is wrong with the code ? I couldn't figure it out..
#include <fstream>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>
using namespace std;
void main (void)
{
std::stringstream stream;
struct tm *ptr;
time_t tm;
char timestamp[60];
string xstr = "This is sample";
for( int n = 1; n <= 5; ++n)
{
tm = time(NULL);
ptr = localtime(&tm);
memset(timestamp,0,sizeof(timestamp));
strftime(timestamp ,100 , "%Y%m%d_%H%M%S",ptr);
stream << "C:\\output\\sample_" << n << "_" << timestamp <<
".txt" ;
std:fstream SaveFile(stream.str().c_str());
for( int j = 1; j <= 10; ++j)
{
SaveFile << xstr << endl;
}
SaveFile.close();
}
}
Thanks. appreciate your kind advise.
Skywalker