move
作者:
孤影渐苍茫 | 来源:发表于
2019-11-24 12:47 被阅读0次
// move example
#include <utility> // std::move
#include <iostream> // std::cout
#include <vector> // std::vector
#include <string> // std::string
int main () {
std::string foo = "foo-string";
std::string bar = "bar-string";
std::vector<std::string> myvector;
myvector.push_back (foo); // copies
myvector.push_back (std::move(bar)); // moves
std::cout << "myvector contains:";
for (std::string& x:myvector) std::cout << ' ' << x;
std::cout << '\n';
std::cout << "foo:" << foo << '\n';
std::cout << "bar:" << bar << '\n';
return 0;
}
myvector contains: foo-string bar-string
foo:foo-string
bar:
本文标题:move
本文链接:https://www.haomeiwen.com/subject/ysdlwctx.html
网友评论