两种方法1命令行重定向比如编译出a.exe使用a.exe<in.txt>out.txt其中<用于重定向输入,>用于重定向输出2代码方式通过freopen函数重定向stdin和stdout比如stdin=freopen("in.txt",stdin);