找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3163|回复: 3

[通用编程] 長度問題

[复制链接]
发表于 2007-12-25 13:26:55 | 显示全部楼层 |阅读模式
  1.                      string st1("foobar");
  2.     string st2("a mighty oak");
  3.     string *ps = &st1;
  4.     cout<< "st1:"<< sizeof(st1)
  5.         << "st2:"<< sizeof(st2)
  6.         << "ps:" << sizeof(ps)
  7.         << "*ps:"<< sizeof(*ps)
复制代码
為什麼  sizeof(ps) 輸出的是4呢?[s:3]
发表于 2007-12-25 18:58:49 | 显示全部楼层
ps不是指针么? *ps才是字符串。
发表于 2007-12-25 20:06:10 | 显示全部楼层
不知道string是什么,如果是STL还是去算一下对象的大小罢- -

至于指针,32B平台总是4BYTES
发表于 2007-12-26 00:55:31 | 显示全部楼层
String类貌似是C++中推荐使用的字符串类
详细内容见http://www.cppreference.com/cppstring/index.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|幻想森林

GMT+8, 2026-11-6 17:25 , Processed in 0.011015 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表