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