将内容输入到文本中、读取文件、将输出结果保存到文件中、计算程序跑的时间(c++)

将数据输出到文件中

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstdlib>
#include<fstream>
#include<time.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const LL INF=1e9+7;
const int maxn=1e5+50;
int a[maxn],b[maxn];//存已经出现过的数 和 没有出现过的数
int main()
{
    srand((unsigned)time(0));//保证随机函数每次跑出来结果都不一样
    ofstream filein;//
    filein.open("a.txt");
    int T;
    T=rand()%3+1;
    filein<<T<<'
';
    return 0;
}

读取文件中的内容,将输出结果存到文件中

    freopen("input8.txt", "r",stdin);
    freopen("output8.txt", "w", stdout);

 计算程序跑的时间,放在main函数开头和结尾:加头文件ctime


int main()
{
  clock_t start,finish;
double totaltime; start=clock(); ....中间是代码 finish=clock(); totaltime=(double)(finish-start)/CLOCKS_PER_SEC; cout<<"此程序的运行时间为"<<totaltime<<"秒!"<<endl;
}
当初的梦想实现了吗,事到如今只好放弃吗~
原文地址:https://www.cnblogs.com/caijiaming/p/11613076.html