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.
std::string test("this is a test string"); test[0] = 'b';
上記のコードのように、文字列の一部が変更されています。コンパイラは新しい文字列を生成しますか、それとも古い文字列を変更しますか?
既存の を変更しstringます。
string
はtest std::string変更できるので「bhis is a test string」になります。文字列の作成に使用される文字列リテラル"this is a test string"は変更されません。
test
std::string
"this is a test string"
のコンストラクターはstring文字配列をコピーします。2 行目はそのコピーを変更します。