but in the char array it's empty too !
why I have to fill string array with "*" ,and in char I haven't ?
remember that string has default size , you can see from :
// x is an array of 10 characters,
// the values of these chars are undefined.
char x[10];
why I have to fill string array with "*" ,and in char I haven't ?
You can use any other character you want. I just picked '*' out of the air because if I specify the size of the string in the constructor I also have to specify their value. I could also have used the resize function.
1 2 3 4
string str;
str.resize(10);
// which is equivalent to
string str(10, '\0');
remember that string has default size
The default size of a string is zero. The max_size() function just gives you an upper limit to what sizes can be handled. 4294967294 is the highest value that can be stored in an unsigned 32-bit number. In a 32-bit address space you will likely run into problems way before reaching that size because the string is not the only thing that use up memory.