如何把样例从文件中输入程序

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int a;
    cin>>a;
    cout<<a*a;
    return 0;
}

提前在程序所在的文件夹中创建in.txt和out.txt

posted @ 2020-02-10 22:35  Tomorrow1126  阅读(232)  评论(0编辑  收藏  举报