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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM