【发布时间】:2017-07-18 17:22:12
【问题描述】:
#include <bits/stdc++.h>
int main () {
std::string foo = "string_1";
std::string bar = "string_2";
std::vector<std::string> myvector;
myvector.push_back (foo);
myvector.push_back (std::move(bar));
for (std::string x:myvector)
std::cout << x << '\n' ;
}
我换的时候那个码怎么不一样
for (std::string x:myvector)
为了?
for (std::string& x:myvector)
我猜有很多地方我可以找到它,但我不知道这个度量的名称是什么,所以我不知道我应该搜索什么。如果它对您来说更容易,那么解释的链接就足够了。
编辑:
有什么区别:
for(auto x:my_vector)
for(auto& x:my_vector)
for(auto&& x:my_vector)
【问题讨论】:
-
这叫做“参考”。
-
不要包含
,它是一个非标准的头文件,并不意味着包含。 -
您建议使用类似于 bist/stdc++.h 的不同标头还是单独包含所有内容?
标签: c++11