我有一套整套的东西;长度52 我在用的循环通过一组这样的迭代:迭代通过一组
for(iterator A from 1st to 48th element)
for(iterator B from A+1 to 49th element)
for(iterator C from B+1 to 50th element)
for(iterator D from C+1 to 51th element)
for(iterator E from D+1 to 52th element)
{
//save the values from the actual positions in set in array[5]
}
首先,我试图用一个迭代来,但后来我意识到,这是不可能的,开始从position of another iterator +1
的迭代器。 然后我试图使用指针,并通过数值跳,但我正确分配只有第一个值,然后,我不能在第二等
我的代码是跳跃:
set<int> tableAll;
for(int i=4; i!=52; ++i)
tableAll.insert(i);
const int * flop1 = & * tableAll.begin();
cout << * flop1 << endl;
flop1++;
cout << * flop1 << endl;
当我cout
的指针flop1
的值,我得到4,这没关系,但是当我在屏幕上增加并且再次cout
时,我得到0,然后是49,然后是0,然后是1,然后是0,而不是5,6,7,8和9。
那么如何正确地遍历我的设置?我假设使用指针会比一些迭代器解决方案更快。
对于集合中第48个元素的理解是什么,因为一个集合没有秩序的概念?也许矢量更适合? –
@LuchianGrigore:假设它是'std :: set',那么它肯定有一个order的概念。 –
从另一个迭代器+ 1的位置开始迭代器有什么困难?只需从其他迭代器初始化迭代器,然后对其进行增量。对于(auto newIterator = oldIterator; ++ NewIterator!= set.end();)从实现的角度来看,@ –