我需要能够在 CLion 中调试输入并将输入重定向到标准输入,但我找不到执行此操作的方法。我能想到的唯一解决方案是将 stdin 设置为文件。
我研究过使用 freopen() 但这在 C99 中似乎无效,我必须在我所在的类(class)中使用它。
最佳答案
不要在你的程序中读取stdin
FILE *input = stdin;
if (debugging) input = fopen("somefile", "r");
// ... use `input`, not `stdin`
if (debugging) fclose(input);
关于c - 在执行期间手动将 stdin 重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58045885/