#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; }