我有一个函数需要能够写入stdout或文件,具体取决于用户想要的.它默认为标准输出.为了实现这一点,我正在做以下(减去错误检查等):
FILE* out;
if (writeToFile) { /*Code to open file*/; }
else
out = stdout;
// ...rest of the function goes here
if (out != stdout)
fclose(out);
Run Code Online (Sandbox Code Playgroud)
这当然可以解决问题,但我不知道它有多便携.如果它不是,和/或它还有另一个问题,我应该怎么做呢?
| 归档时间: |
|
| 查看次数: |
377 次 |
| 最近记录: |