c++ sizeof( string )

后端 未结 8 1524
陌清茗
陌清茗 2020-12-09 13:59
#include 
#include 

int main(int argc, char *argv[])
{
   cout << "size of String " << sizeof( string );
               


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 14:36

    A string object contains a pointer to a buffer on the heap that contains the actual string data. (It can also contain other implementation-specific meta-information, but yours apparently doesn't.) So you're getting the size of that pointer, not the size of the array it points to.

提交回复
热议问题