[英]c++: std::advance (once) goes to end of 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
毫無疑問,我只是想念一些愚蠢的東西,但是有人可以幫我嗎?
您沒有正確使用std::distance
。 begin
迭代器是第一個參數,例如
distance(StringOfPearls->begin(), DNAreplicase)
這是所有函數的約定,這些函數采用一對表示范圍的迭代器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.