如何获得c++ iostream的FileHandle ?

How do I get the FileHandle for a C++ iostream?

本文关键字:FileHandle iostream 何获得 c++      更新时间:2023-10-16

我需要与Windows上使用mingw的c++ iostream相关联的Windows FileHandle。这可能与Windows上与c++ iostream关联的UNIX文件描述符相同。有人知道怎么找吗?谢谢。

你看到我的答案了吗?
我如何在win32上刷新stdlib输出文件?

std::basic_filebuf<char> *file_buf = dynamic_cast<std::basic_filebuf<char> *>(f.rdbuf());
if (file_buf != 0) {
    struct to_get_protected_member : public std::basic_filebuf<char> {
        int fd() { return _M_file.fd(); }
    };
    printf("your fd is %dn", static_cast<to_get_protected_member *>(file_buf)->fd());
}