freopen("data.txt", "r", stdin)之后,cin会被直接跳过。很多博客在写需要
freopen("CON", "r", stdin)
(Windows)
或者
freopen("/dev/tty/", "r", stdin)
(Linux)
但是实际遇到问题时发现,需要先fclose(stdin)
关闭文件流,然后通过cin.clear()
清除输入流,最后再通过上述重定向命令定向回控制台的输入。
原文:https://www.cnblogs.com/Rane/p/13179982.html