0

我从来没有遇到过迭代器的以下问题,所以我真的不知道解决方案可能从哪里开始。我有一个列表“StringOfPearls”,在我执行以下操作之前已对其进行了置换:

DNAr = StringOfPearls->begin(); // Added 1 element to the beginning of this list in earlier line of code
cout << "pos DNAr before bumping by 1: " << distance(DNAreplicase, StringOfPearls->begin()) << endl;
advance(DNAreplicase, 1);
cout << "pos DNAr after bumping by 1: " << distance(DNAreplicase, StringOfPearls->begin()) << endl;

回报:

pos DNAr before bumping by 1: 0
pos DNAr after bumping by 1: 10

毫无疑问,我只是错过了一些愚蠢的事情,但是有人可以帮助我吗?

4

1 回答 1

0

你没有std::distance正确使用。begin迭代器是第一个参数,例如

distance(StringOfPearls->begin(), DNAreplicase) 

这是所有采用一对表示范围的迭代器的函数的约定。

于 2017-09-19T09:38:09.183 回答