samedi 17 novembre 2018

How to declare a std::array of variable length globally and get its size if it has std::string as member

In C we can create a static global array like below:

static struct A a1 [] = { 1,2,3,4};

So we can determine the size using below calculation

sizeof(a1)/sizeof(a1[0])

How can we achieve the same in C++ using std::array if it contains std::string of variable length values strings:

struct A
{
std::string b;
int x;
};

Aucun commentaire:

Enregistrer un commentaire