#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