c++ 用freopen简单的重定向,再也不怕debug了~

#define debug  //去掉此句话,重定向部分失效
#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    #ifdef debug
    freopen("D:\\in.txt","r",stdin); //从in.txt文件输入
    freopen("CON","r",stdin);   //从控制台读入
    freopen("D:\\out.txt","w",stdout);//输出到out.txt文件
    freopen("CON","w",stdout);//从控制台输出
    #endif
    
    int a;
    cin>>a;
    cout<<a<<endl;
    fclose(stdin);
    fclose(stdout);//关闭文件
    return 0;
}

  

posted @ 2016-11-29 00:36  TomJarry  阅读(2760)  评论(0编辑  收藏  举报