1
#include<list>
#include<iostream>
using namespace std;
list<int> DL,TRS;
list<int>::iterator gitr;
void exchange();
int main() {
DL.push_back(10);
gitr=DL.begin();
TRS.push_back(11);
TRS.push_back(12);
exchange();
cout<<(*gitr)<<endl;
}
void exchange() {
list<int> tdl;
tdl=DL;
DL.clear();
DL=TRS;
list<int>::iterator tmpitr=DL.begin();
for(;tmpitr!=DL.end();++tmpitr)
cout<<(*tmpitr)<<endl;
DL.clear();
DL=tdl;
}
これは10の代わりに11を出力します。なぜですか?グローバルイテレータをリストにリセットする
なぜ10を出力すると思いますか? –
あなたのコードを再フォーマットしましたが、空白はあなたの友人であることに注意してください。 –
しかし、あなたはコードの後に質問を削除しました。 – crashmstr