我想输出C++程序运行到桌面上名为C10.txt的文件所需的时间。我想运行该程序100次,然后当我打开文件时,它会告诉我程序运行的所有不同时间。我知道我需要fstream来做到这一点,但我不知道该从哪里去。这是我想多次运行的代码。我应该添加什么来完成这项工作?通过多次运行程序以C++多次输出文件
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
void merge(int*,int,int);
void mergeSort(int*,int,int);
const int ARRAYSIZE = 10;
int main()
{
clock_t startTime = clock();
srand(unsigned(time(0)));
cout << (double(clock() - startTime)/(double)CLOCKS_PER_SEC) * 1000000<< " microseconds." << endl;
return 0;
}
首先,谢谢你的帮助!其次,使用上面的代码,我现在可以将时间添加到C10.txt文档中,但每次运行该程序时,C10.txt文档中的时间都会更改。我希望每次运行程序时,新的时间都会被添加到C10.txt文件 – Mayankmmmx
'ofstream yournamehere(“path_to_desktop \ C10.txt”,ios :: app);'那么就是。 –