文件输出中的有限值
limited value in a File output
我有一个返回执行时间的程序,每次运行的输出显示在同一行的文件中。
#include <iostream>
#include <fstream>
#include <math>
#include <boost>
using namespace std;
int main() {
std::ofstream file("MyFile.txt",std::ios_base::app);
v2 = rand() % 100 + 1; // just to burn some time
std::cout << v2 ; // just to burn some time
boost::chrono::duration<double> sec = boost::chrono::system_clock::now() - start;
file<<sec.count() << ";";
file.close();
return 0 ;
}
4运行后,文件中的输出如下:
0.0190567;4.92035;11.0541;13.1457;
我希望在30次运行后,第30次结果必须以换行符显示。没有任何增加的函数或循环,这将影响运行时的持续时间。我认为还有其他的方法来格式化输出文件通过awk sed。
您可以使用awk。
awk '{ gsub(/([0-9]+(.[0-9]*)?;){30}/, "&n"); print }' MyFile.txt
这应该在每30个;
之后插入一个n
相关文章:
- 有没有办法简单地从 GPU 调用多个 cpp 输出文件?
- VI工作室代码错误无法打开输出文件主.exe
- 在代码块中查找输出文件
- 将未签名的字符写入输出文件
- 为什么我的代码不写入输出文件?
- 完成搜索任务时为空输出文件
- 如何将地图<列表<string>、矢量<string>>输出到输出文件?
- 无法在代码块 IDE 中打开输出文件.exe
- C++:更改 IF 语句中的输出文件
- 编译 gsoap 输出文件 (onvif) 时出现问题
- C++击球平均值程序使用输入/输出文件打印名称,平均值,最高/最低平均值时遇到麻烦
- while 循环中的流输出文件() 通常生成空文件
- 如何使用 Docker 访问输出文件
- 提升进程间共享内存删除、权限和输出文件
- 查找素数,然后将质数放入输出文件中
- GDB / C++ - 根据循环条件将多个变量记录到输出文件中
- 带有文件结束函数的 while 循环重复输出文件中的最后一个数字两次
- 我的输出文件未显示解决方案
- 输入文件中的第一个字符是输出文件中的最后一个字符,反之亦然
- C++,我正在尝试创建一个有效的.bmp输出文件