有没有指向什么的文件指针(FILE *)? [英] Is there a file pointer (FILE*) that points to nothing?
本文介绍了有没有指向什么的文件指针(FILE *)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某些原因,我需要一个指向任何内容的文件指针(FILE *)。这意味着我可以将它传递给fprintf函数和fprintf忽略文件指针。
For some reasons I need a file pointer (FILE*) that points to nothing. It means I can pass it to fprintf function and fprintf ignore the file pointer.
例如:
void my_function()
{
FILE* nothing = NULL; // NULL is not correct.
int n = fprintf(nothing, "PI = %f", 3.14); // Note: When nothing = NULL, error ocured.
}
有没有指向任何东西的文件指针(FILE * p>
Is there a file pointer (FILE*) that points to nothing?
推荐答案
否。
您的代码将导致运行时异常。例如,如果你在支持它的操作系统上运行,你可以使用 / dev / null
,但是在C ++中没有内置的。
Your code will cause a run-time exception. You can use /dev/null
for example, if you're running on an OS that supports it, but there's nothing like that built-in in C++.
这篇关于有没有指向什么的文件指针(FILE *)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文