0
点赞
收藏
分享

微信扫一扫

C++ for (auto &it:myset) &是什么意思 引用

蒸熟的土豆 2022-01-25 阅读 49


加了&代表引用,如果不加,则是值拷贝


#include <iostream>
#include <set>

using namespace std;

int main()
{

// cbegin/cend(c++11): Returns a const_iterator pointing to the first element in the container/
// Returns a const_iterator pointing to the past-the-end element in the container
std::set<int> myset = { 50, 20, 60, 10, 25 };

std::cout << "myset contains:";
for (auto it:myset)
std::cout << ' ' << it;

std::cout << '\n';

std::cout << "myset contains:";
for (auto &it:myset)
std::cout << ' ' << it;

system("pause");
return 0;
}

C++ for (auto &it:myset) &是什么意思 引用_c++11


举报

相关推荐

0 条评论