fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <Windows.h>
  5. #include <sstream>
  6. #define N 1024
  7. #define Nx 1024
  8.  
  9. using namespace std;
  10.  
  11.  
  12. void writeFile( float *data, string fileName)
  13. {
  14. ofstream out(fileName.c_str());
  15. for (int i = 0; i < N; i++)
  16. {
  17. for (int j = 0; j < Nx; j++)
  18. {
  19. out << data[j +i*Nx] << "\t";
  20. }
  21. out << '\n';
  22. }
  23. out.close();
  24. return;
  25. }
  26.  
  27.  
  28. void writeFile2( float *data, string fileName)
  29. {
  30. ofstream out(fileName.c_str());
  31. stringstream ss("");
  32. string os("");
  33. for (int i = 0; i < N; i++)
  34. {
  35. for (int j = 0; j < Nx; j++)
  36. {
  37. ss.str(string());
  38. ss << *(data+i*Nx+j);
  39. ss >> os ;
  40. out.rdbuf()->sputn(os.c_str(),strlen(os.c_str()));
  41. out.rdbuf()->sputn("\t",sizeof(char));
  42. }
  43. out.rdbuf()->sputn("\n",sizeof(char));
  44. out.flush();
  45. }
  46. out.flush();
  47.  
  48. out.close();
  49. return;
  50. }
  51.  
  52.  
  53. int main()
  54. {
  55.  
  56.  
  57. float *data =NULL ;
  58. data = new float[N*Nx]();
  59.  
  60. fill(data, data+N*Nx, 9.9f);
  61. DWORD s = GetTickCount();
  62. //writeFile( data,"ouput.txt");
  63. DWORD d = GetTickCount();
  64. cout<<(d - s) / 1000.f<<endl;
  65.  
  66. s = GetTickCount();
  67. writeFile2( data,"ouput2.txt");
  68. d = GetTickCount();
  69. cout<<(d - s) / 1000.f<<endl;
  70.  
  71. delete data;
  72. return 0;
  73. }//end of main
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:21: fatal error: Windows.h: No such file or directory
 #include <Windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty