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

2020-12-13 15:36

阅读:357

标签:freopen   c++   ota   tor   ons   inf   ++   alt   nbsp   

将数据输出到文件中

#include
#include
#include
#include
#include
#include
#include
#include
#include
#includeusing 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\n;
    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"此程序的运行时间为""秒!"}

 

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

标签:freopen   c++   ota   tor   ons   inf   ++   alt   nbsp   

原文地址:https://www.cnblogs.com/caijiaming/p/11613076.html


评论


亲,登录后才可以留言!