ofstream output (filename.c_str());for (int j = 0; j < dim; j++){ for (int i = 0; i < dim; i++) output << arrayPointer[j * dim + i] << " "; output << endl;}
这似乎是一个非常慢的 *** 作,是一种更有效的方式输出像这样的文本文件到硬盘驱动器?
更新:
考虑到这两个建议,新代码如下:
ofstream output (filename.c_str());for (int j = 0; j < dim; j++){ for (int i = 0; i < dim; i++) output << arrayPointer[j * dim + i] << "\t"; output << "\n";}output.close();
以500KB / s的速度写入HD
但这写入HD为50MB / s
{ output.open(filename.c_str(),std::ios::binary | std::ios::out); output.write(reinterpret_cast<char*>(arrayPointer),std::streamsize(dim * dim * sizeof(double))); output.close();}解决方法 使用C IO,它比C IO快很多.我听说编程竞赛中的人们因为使用C IO而不是C IO而超时.
#include <cstdio>file* fout = fopen(filename.c_str(),"w");for (int j = 0; j < dim; j++) { for (int i = 0; i < dim; i++) fprintf(fout,"%d\t",arrayPointer[j * dim + i]); fprintf(fout,"\n");} fclose(fout);
只需将%d更改为正确的类型即可.
总结以上是内存溢出为你收集整理的c – 更快地创建制表符分隔文本文件的方法?全部内容,希望文章能够帮你解决c – 更快地创建制表符分隔文本文件的方法?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)