0
#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)
這就是所謂的「參考」。 –
的可能的複製[C++拷貝構造的語法:是符號參考R/L值?](https://stackoverflow.com/questions/33290801/c-copy-constructor-syntax-is-ampersand-reference-to-rl - 值) –
不包括<比特/ STDC++。H>,它是一個非標準報頭,並不意味着列入。 – 2017-07-18 19:14:56