简体   繁体   中英

C/C++ library for platform-independent binary file I/O

I've been trying for months to find a small C or C++ library for platform-independent binary file I/O, that means endian swapping and with fixed size types.

I know that huge libraries like wxWidgets and Qt have them, and that languages like Java and C# also have them, but I'd prefer to use a small library instead of a huge framework.

How about Google Protocol Buffers ?

The library includes bindings for C++, Java and Python.

Have a look at Boost.Serialization

One of it's goals is "Data Portability - Streams of bytes created on one platform should be readable on any other."

There are also links to other libraries providing similar functionality.

Why not just use fstream that comes packaged in with all C++ compilers. You just set the ios::binary flag and make plentiful use of sizeof to make it OS independent. Eg: http://courses.cs.vt.edu/~cs2604/fall02/binio.html and http://www.codersource.net/c/c-tutorial-on-file-operations/c-file-io-binary-files-using-fstream.aspx

对于大多数文件格式的工作,我更喜欢使用sqlite: http ://www.sqlite.org/很棒的事情是您可以跨操作系统编程语言设备访问相同的数据文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM