Python's struct.pack/unpack equivalence in C++
Question: I used struct.pack in Python to transform a data into serialized byte stream.

    
    
    >>> import struct
    >>> struct.pack('i', 1234)
    '\xd2\x04\x00\x00'
    

What is the equivalence in C++?


Answer: There isn't one. C++ doesn't have built-in serialization.

You would have to write individual objects to a byte array/vector, and being
careful about [endianness](http://en.wikipedia.org/wiki/Endianness) (if you
want your code to be portable).

