摘要:
C++11支持range-based for循环。这是一个很方便的特性,能省挺多代码。以下代码就能很方便的遍历vector中的元素,并打印出来:std::vector<int> int_vec;int_vec.push_back(1);int_vec.push_back(2);//如果要修改int_vec中的元素,将变量x声明为 int& 即可for (int x: int_vec){ std::cout << x << endl;}可以遍历的对象包括:数组。(不包括指针)定义了begin()和end()方法,且返回该方法返回迭代器的类对象。(STL 阅读全文
posted @ 2013-06-02 12:15
h46incon
阅读(31424)
评论(2)
推荐(2)

浙公网安备 33010602011771号