[英]How get fileName having FILE*?
In my class I have FILE* ascii_file;
在我班上我有FILE* ascii_file;
data member, which always is initialized via class constructor. 数据成员,始终通过类构造函数初始化。 How can I get full path of the asci_file
? 如何获取asci_file
完整路径? I don't want to store more information about the file expect ascii_file
, and want it to work on windows, linux and solaris. 我不想存储有关文件期望ascii_file
更多信息,并希望它可以在windows,linux和solaris上运行。
Here is a solution for Linux: 这是Linux的解决方案:
This task is going to require non-portable code. 此任务将需要不可移植的代码。
On Windows you can convert FILE*
to CRT file descriptor using _fileno , and then convert to an OS handle using _get_osfhandle . 在Windows中,你可以转换FILE*
使用CRT的文件描述符_fileno ,然后使用转换为OS手柄_get_osfhandle 。
Then you can get the filename as shown here (using file mapping). 然后你可以得到这里显示的文件名(使用文件映射)。
Obtaining a File Name From a File Handle 从文件句柄中获取文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.