c++获取读写文本权限

#include<cstdio>
#include<iostream>
#include<fstream>
using namespace std;
int tot;
int main(){
    ifstream infile("1.txt",ios::in);//没有不报错 
    infile>>tot;
    cout<<++tot<<endl;//输出到屏幕 
    infile.close();
    ofstream outfile("1.txt",ios::out);
    outfile<<tot;
    outfile.close();
    //用处大大的 
    return 0;
}

 同理

#include<cstdio>
#include<iostream>
using namespace std;
int tot;
int main(){
    freopen("1.in","r",stdin);
    scanf("%d",&tot);
    fclose(stdin);
    freopen("1.in","w",stdout);
    tot++;
    printf("%d",tot);
    fclose(stdout);
    return 0;
}

 

posted @ 2016-06-27 16:55  神犇(shenben)  阅读(825)  评论(0编辑  收藏  举报