c++读入挂/输入输出流 c语言文件读入读出

输入挂

void in(long long &x){
    long long ff=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=ff;
}

关闭同步流(注意不要跟scanf和printf混用)

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

C语言文件读入/读出

    int n;
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int tim=0;
    while(cin>>n){
        cout<<tim++<<":"<<n<<endl;
    }
    fclose(stdin);
    fclose(stdout);

 

posted @ 2020-08-11 22:48  杯酒朝阳  阅读(259)  评论(0编辑  收藏  举报