cross-platform從std :: fstream
The primary reason for seeking a conversion from std::fstream to FILE* is the lack of cross-platform support for an natively available solution.
Limitations of不幸的是,std :: fstream實現沒有直接的方法來從std :: fstream對像中提取文件句柄。 This is because the implementation of std::fstream is not standardized to use FILE, leaving it at the discretion of the underlying implementation.
Alternatives to Conversion
As a result, it is not recommended to attempt a conversion between std::fstream and FILE*.相反,請考慮以下替代方案: 使用C包裝器函數:
編寫一個接受std :: fstream並提供文件*界面的包裝函數。對象,包括std :: fstream。考慮funopen()(non-posix):
儘管不是posix api,funopen()允許您創建一個文件對象並指定自定義文件操作。您可以使用std :: fstream對象編寫函數來處理讀,寫,尋求和關閉操作。免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3