注册 登录
编程论坛 C++教室

关于C++字符串的问题,求任何比我厉害的人进入

八画小子 发布于 2011-08-10 20:41, 686 次点击
想问一个问题 VS2010中,字符串除了末位的'\0',最大包含的字符为2328,这和char型数组不同。
问题1  2328是如何得到的
问题2  为什么两者不相同,是不是内部设计不同?
8 回复
#2
loveshuang2011-08-10 22:22
    C++中的字符串末尾有'\0',吗???
#3
八画小子2011-08-10 23:05
你说呢?
#4
baobaoisme2011-08-10 23:19
应该没有吧,要不c_str()这个函数用来做什么
#5
qq510990082011-08-10 23:55
“为了兼容C,C++中所有的字符串字面值都由编译器自动在末尾添加一个空字符”
#6
baobaoisme2011-08-11 00:24
楼上同学,字符串字面值可跟C++的字符串类型不一样的哦。
"hello"这样用双引号括起来的叫作字符串字面值。
字符串类型是用string类型来定义的,比如string s="hello"; s是一个字符串。

ps:查了下,string类型应该是有'\0'来结尾的。
另外附上一个以前的帖子
https://bbs.bccn.net/thread-291590-1-1.html

[ 本帖最后由 baobaoisme 于 2011-8-11 00:49 编辑 ]
#7
lucky5635912011-08-11 09:20
字符串末尾本来就要补0
#8
玩出来的代码2011-08-11 19:57
string::c_str
Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.
A terminating null character is automatically appended.

string::data
Returns a pointer to an array of characters with the same content as the string.
Notice that no terminating null character is appended

The null character ' \0 ' is used as a special character in a C-string to mark the end of the string but has no special meaning in an object of type string
#9
icecream2352011-08-12 13:57
vs2010有使用教程嘛,我还在用vc6
1