我从未使用迭代器进入以下问题,所以我真的不知道解决方案可能从哪里开始。我有一个LIST" 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
毫无疑问,我只是错过了一些愚蠢的事情,但任何人都可以帮助我吗?
答案 0 :(得分:0)
您没有正确使用std::distance
。 begin
迭代器是第一个参数,例如
distance(StringOfPearls->begin(), DNAreplicase)
这是所有函数的约定,它们使用表示范围的迭代器对。