C++ Move Posted on 2019-06-11 How to use C++ move? Just like this: 123456789101112131415161718192021222324252627282930313233343536373839#include <iostream>#include <string>#include <vector>void fun(std::string& str){ std::cout << "l-value reference, str=" << str << std::endl; std::string temp_str(std::move(str)); std::cout << "temp_str = move(str), now str=" << str << std::endl; std::cout << "temp_str=" << temp_str << std::endl;}void fun(std::string&& str){ std::cout << "get r-value reference, build a lvalue str" << std::endl; std::cout << "now str=" << str << std::endl; std::string temp_str(std::move(str)); std::cout << "temp_str = move(str), now str=" << str << std::endl; std::cout << "temp_str=" << temp_str << std::endl;}void array_move(){ std::cout << "array move test" << std::endl; std::vector<char> array = {'h', '2'}; std::vector<std::vector<char>> array_vector; array_vector.push_back(std::move(array)); std::cout << "after move, the size of array :" << array.size() << std::endl;}int main(){ std::string str = "hello,world"; fun(str); std::cout << "after move main: str=" << str << std::endl; fun("good"); array_move(); return 0;}