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

标签 c clion

我需要能够在 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/

相关文章:

c - 如何区分管道和交互式标准输入

python - 寻找一种轻量级解决方案来系统地检测 C 函数的 if 条件

c - 在xv6源代码的 'user.h'中使用__attribute__((noreturn))作为退出函数声明?

c++ - Clion 警告 glm::dot returnType 但无论如何编译

intellij-idea - 对保存在 IntelliJ 或 CLion 中的文件执行 rustfmt

intellij-idea - 如何在IntelliJ的REST客户端中将文件作为POST请求的参数发送?

结合openmp和sse指令

c - 在 Xcode 中,链接器命令失败,退出代码为 1

c++ - CLion 行注释的自动缩进不一致

c++ - CLION -- 如何为 CMakeLists.txt 文件中未提及的应用程序创建和调试配置