在执行期间手动将stdin重定向到文件

时间:2019-09-22 03:51:14

标签: c clion

我需要能够在CLion中调试输入并将其重定向到stdin,但是我找不到解决方法。我唯一想到的解决方案是将stdin设置为文件。

我研究过使用freopen(),但这在C99中似乎是无效的,必须在我所在的类中使用。

1 个答案:

答案 0 :(得分:1)

不要在程序中读取stdin

FILE *input = stdin;
if (debugging) input = fopen("somefile", "r");
// ... use `input`, not `stdin`
if (debugging) fclose(input);
相关问题