lundi 2 novembre 2015

How to initialize a std::array

I have a file structure where fixed length strings have no trailing zero. How to initialize fields as std::array without trailing zero:

#pragma pack(push, 1)
struct Data {
    // Compiles, but it has an undesired '\0':
    std::array<char, 6> undesired_number{"12345"};
    // Does not compile:
    std::array<char, 5> number{"12345"}; // stripping '\0'
};
#pragma pack(pop)

Aucun commentaire:

Enregistrer un commentaire