Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

习题3.9使用下标访问空字符串 #20

Open
blacklzx opened this issue Apr 3, 2021 · 1 comment
Open

习题3.9使用下标访问空字符串 #20

blacklzx opened this issue Apr 3, 2021 · 1 comment

Comments

@blacklzx
Copy link

blacklzx commented Apr 3, 2021

既然空字符串存在1个元素\0,使用下标0去访问它应该是合法的,经检验也是可行的。

@blacklzx blacklzx closed this as completed Apr 3, 2021
@blacklzx blacklzx reopened this Apr 3, 2021
@AXDHY
Copy link
Contributor

AXDHY commented Jan 19, 2023

但是书中76页中初始化string对象的方式中第4行提到,使用字符串字面值初始化string类型时,并不会将字符串字面值隐含的'\0'存入string类型对象中.而且表格上面也提到,string对象中没有任何字符.
故我推测默认初始化,空串中也不包含任何元素.而且空字符串的size()是0.而且字符串的下标是小于s.size()的,故还是不合理的.但这个问题确实无关紧要.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants