• 将内容输入到文本中、读取文件、将输出结果保存到文件中、计算程序跑的时间(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;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    Effective C++学习笔记之explicit
    腾讯面试经验2
    腾讯面试经验
    值类型和引用类型的区别,struct和class的区别
    【转载】固态硬盘的S.M.A.R.T详解
    SSD的传输总线、传输协议、传输接口
    坏块管理(Bad Block Management,BBM)
    脱离SVN的控制
    Func的介绍
    简单AOP
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11613076.html
Copyright © 2020-2023  润新知