返回信息流string s;
cout << s[0] ;
s的长度明明是0,为什么程序还能运行?运行结果貌似输出空格
这是一条镜像帖。来源:北邮人论坛 / cpp / #77246同步于 2014/3/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
STL中的string
origin
2014/3/1镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
当string []访存的下标等于string::size()时,返回字符串结尾符'\0'
【 在 origin 的大作中提到: 】
: [code=c]
: string s;
: cout << s[0] ;
: ...................
用vs运行,build succeed,但是debug assertion fail,提示string subscript out of range,看来不同编译器还是不一样的
string为空的实现方式:
public:
String()
: data(new char[1])
{
*data = '\0';
}
private:
char *data;
【 在 origin 的大作中提到: 】
: [code=c]
: string s;
: cout << s[0] ;
: ...................
来自「北邮人论坛手机版」