#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
#include <sstream>
#define N 1024
#define Nx 1024
using namespace std;
void writeFile( float *data, string fileName)
{
ofstream out(fileName.c_str());
for (int i = 0; i < N; i++)
{
for (int j = 0; j < Nx; j++)
{
out << data[j +i*Nx] << "\t";
}
out << '\n';
}
out.close();
return;
}
void writeFile2( float *data, string fileName)
{
ofstream out(fileName.c_str());
stringstream ss("");
string os("");
for (int i = 0; i < N; i++)
{
for (int j = 0; j < Nx; j++)
{
ss.str(string());
ss << *(data+i*Nx+j);
ss >> os ;
out.rdbuf()->sputn(os.c_str(),strlen(os.c_str()));
out.rdbuf()->sputn("\t",sizeof(char));
}
out.rdbuf()->sputn("\n",sizeof(char));
out.flush();
}
out.flush();
out.close();
return;
}
int main()
{
float *data =NULL ;
data = new float[N*Nx]();
fill(data, data+N*Nx, 9.9f);
DWORD s = GetTickCount();
//writeFile( data,"ouput.txt");
DWORD d = GetTickCount();
cout<<(d - s) / 1000.f<<endl;
s = GetTickCount();
writeFile2( data,"ouput2.txt");
d = GetTickCount();
cout<<(d - s) / 1000.f<<endl;
delete data;
return 0;
}//end of main
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPFdpbmRvd3MuaD4KI2luY2x1ZGUgPHNzdHJlYW0+CiNkZWZpbmUgTiAxMDI0CiNkZWZpbmUgTnggMTAyNAoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgp2b2lkIHdyaXRlRmlsZSggZmxvYXQgKmRhdGEsIHN0cmluZyBmaWxlTmFtZSkKewogICAgb2ZzdHJlYW0gb3V0KGZpbGVOYW1lLmNfc3RyKCkpOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBOOyBpKyspCiAgICAgICAgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgTng7IGorKykKICAgICAgICB7CiAgICAgICAgICAgICBvdXQgPDwgZGF0YVt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