Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
Variable
Hello, While coding you have noticed that if you select float or int data type for string data.. Error says, Can't convert to float from 'const char*' And this two words also help you to create a string type variable.. Now the question is, Does, c++ counts strings as an constant array of characters?? https://code.sololearn.com/crbf4UI58Wd3/?ref=app Another thing const char* - - - 8bits string - - - 32bits Why??
2 ответов
+ 1
C++ string can not be seen as a character array because the quality of changeable length of characters. As we all know array is fixed sized.
std::string works like array because you access the character like you do in array, but in reality it's not an array.
About sizeof, An array is a type that allocate a continuous memory to store the elements of the same data type, while std::string is a class and rather complicated.
We do not really know how std::string is implemented, but since it's a class, we can guess that it has other various members and functionality which potentially increase the size of a string.
0
Roger that