Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么会这样:
char SourceChar = Text.c_str()[Index]; 编译,但是
char SourceChar = Text.c_str()[Index];
char SourceChar = Text.c_str().at(Index); 才不是?有解决方法吗?
char SourceChar = Text.c_str().at(Index);
Text.c_str() 返回一个 'const char *' 这是一个 C 类型,所以它不是一个对象。您只能使用 Text[i] 或 *(Text + i) 访问它的值。
如果您想以更加面向对象的方式访问第 i 个字符,您可以使用 Text[i] 或 Text.at(i)。