mercredi 17 octobre 2018

How does the std::string constructor handle char[] of fixed size?

How does the string constructor handle char[] of a fixed size when the actual sequence of characters in that char[] could be smaller than the maximum size?

char foo[64];//can hold up to 64
char* bar = "0123456789"; //Much less than 64 chars, terminated with '\0'
strcpy(foo,bar); //Copy shorter into longer
std::string banz(foo);//Make a large string

In this example will the size of the banz objects string be based on the original char* length or the char[] that it is copied into?

Aucun commentaire:

Enregistrer un commentaire