august 发表于 2007-12-25 13:26:55

長度問題


                     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呢?

shawind 发表于 2007-12-25 18:58:49

ps不是指针么? *ps才是字符串。

lw 发表于 2007-12-25 20:06:10

不知道string是什么,如果是STL还是去算一下对象的大小罢- -

至于指针,32B平台总是4BYTES

Zelsazgh 发表于 2007-12-26 00:55:31

String类貌似是C++中推荐使用的字符串类
详细内容见http://www.cppreference.com/cppstring/index.html
页: [1]
查看完整版本: 長度問題