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.
挿入キーをオンにしてエディターで行う方法を意味します。
したがって、次のような文字列があります。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
効果は次のとおりです。
~~~~~~~~~~Hello!~~~~~~~~~~~~~~~~~~
つまり、文字列の長さは変わりません。
文字列の一部の上書きは、std::stringのreplaceメンバー関数のいくつかのオーバーロードの 1 つを使用して行われます。次に例を示します。
std::string
replace
string str = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; string rep = "Hello!"; cout << str.replace(5, rep.size(), rep) << endl;
この例は ideone [link]で試すことができます。
最も簡単な解決策はstd::copy、適切なイテレータと共に を使用することです。
std::copy
std::copy( newText.begin(), newText.end(), str.begin() + n );
ターゲット文字列が十分に大きいことを確認してください。