長度問題
string st1("foobar");
string st2("a mighty oak");
string *ps = &st1;
cout<< "st1:"<< sizeof(st1)
<< "st2:"<< sizeof(st2)
<< "ps:" << sizeof(ps)
<< "*ps:"<< sizeof(*ps)
為什麼sizeof(ps) 輸出的是4呢? ps不是指针么? *ps才是字符串。 不知道string是什么,如果是STL还是去算一下对象的大小罢- -
至于指针,32B平台总是4BYTES String类貌似是C++中推荐使用的字符串类
详细内容见http://www.cppreference.com/cppstring/index.html
页:
[1]