C++文件输入输出

版权声明:来自星空计算机团队(QQ群:134826825)——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/84971463

ACM中巧用文件的输入输出来改写acm程序的输入输出

经常有见大神们使用文件来代替ACM程序中的IO,尤其是当程序IO比较复杂时,可以使自己能够更专注于代码的测试,而不是怎样敲输入。

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=10000;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;

int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);  
    //cout << "Hello world!" << endl;    
    return 0;
}

其中关键就在于

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#define DEBUG
using namespace std;
int n;
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);  
    //cout << "Hello world!" << endl;    
    return 0;
}

而要取消文件输入只要

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
int n;
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);  
    //cout << "Hello world!" << endl;    
    return 0;
}

就是注释掉

//#define DEBUG

 然后这个input.in文件一定要放在程序所在目录下

我用的是CB就是这样子

如果把输出打开的话

输出的output.out文件也会在这个目录下

 

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/84971463