dimanche 21 août 2016

move strings into another string of enough capacity

int main() {
   std::string str;
   str.reserve(9999);

   {
      std::string s1("aaa");
      std::string s2("bbb");
      // can both strings s1, s2 be moved to str?
      // for example str should be "aaabbb"
    }

}

My question is it possible to steal the memory of s1 and s2 to form a concatenated str of s1 and s2 (since it already has enough space for both).

Aucun commentaire:

Enregistrer un commentaire