如何从一个文件描述符文件指针? [英] How to get a FILE pointer from a file descriptor?
本文介绍了如何从一个文件描述符文件指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在玩弄mkstemp(),它提供了一个文件描述符,但我想通过生成fprintf中格式化输出()。有一个简单的方法来改变由mkstemp()进入FILE *结构所提供的文件描述符是适用于使用fprintf中()?
I'm playing around with mkstemp(), which provides a file descriptor, but I want to generate formatted output via fprintf(). Is there an easy way to transform the file descriptor provided by mkstemp() into a FILE * structure that is suitable for use with fprintf()?
推荐答案
使用<一个href=\"http://pubs.opengroup.org/onlinepubs/009604499/functions/fdopen.html\"><$c$c>fdopen()$c$c>:
FILE* fp = fdopen(fd, "w");
这篇关于如何从一个文件描述符文件指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文