C++, best way to change a string at a particular index

前端 未结 4 992
余生分开走
余生分开走 2020-12-24 13:02

I want to change a C++ string at a particular index like this:

string s = \"abc\";
s[1] = \'a\';

Is the following code valid? Is this an a

4条回答
  •  佛祖请我去吃肉
    2020-12-24 13:41

    Yes. The website you link has a page about it. You can also use at function, which performs bounds checking.

    http://www.cplusplus.com/reference/string/string/operator%5B%5D/

提交回复
热议问题