【发布时间】:2012-09-11 21:43:37
【问题描述】:
寻找组合涉及同一容器上的两个循环。
the first iterates over elements:
pick an element
iterate over the elements on the left
print the first and the second iterated elements
所以这是一个错误的例子:
vector<int> vec;
for(size_t i=0; i< 10 ; ++i) vec.push_back(i);
for(auto i : vec)
{
auto j = i.increaseBy(1);
for(j : vec) cout << i << j << "\n";
}
在这个问题中,我感兴趣的是范围循环的语法是否不仅仅是一种简单的迭代元素的方法。没有太多关于 c++11 的文档。
【问题讨论】:
-
它用于迭代容器的所有元素。您无法定义自己的起点或终点。
标签: c++ for-loop c++11 iterator combinations