I need to combine some lines into one, and for an effective reason, I want to use move semantics in this situation (and, of course, these lines will no longer be used). So I tried
#include <iostream> #include <algorithm> #include <string> int main() { std::string hello("Hello, "); std::string world("World!"); hello.append(std::move(world)); std::cout << hello << std::endl; std::cout << world << std::endl; return 0; }
I assumed that he would deduce
Hello, World!
But it actually outputs
Hello, World! World!
This will do the same if you replace append with operator+= . What is the right way to do this?
I am using g ++ 4.7.1 on debian 6.10
source share