両端キューの末尾を指す反復子を返す。
注意:最後の要素の次の指す反復子
| const_iterator end() const; iterator end(); |
#include <iostream>
#include <deque>
#include <cstdio>
using namespace std;
int main()
{
deque<int> ob;
deque<int>::iterator p, p2;
int i;
for(i=0; i<10; ob.push_back(i++)) ;
p = ob.end() - 1;
cout << *p << " ";
while(p != ob.begin()) {
p--;
cout << *p << " ";
}
cout << "\n\n-------------------------------------------\n\n";
cout << "endは両端キューの最後の要素の次の要素を指す反復子を返す\n\n";
cout << "操作1\n";
p = ob.begin();
for(i=0; i<ob.size()+1; i++) {
cout << *p << " ";
p++;
}
p = ob.end();
cout << "\nob.end()が指す値: " << *p << "\n\n";
cout << "操作2\n";
ob.push_back(0);
p2 = ob.begin();
for(i=0; i<ob.size()+1; i++) {
cout << *p2 << " ";
p2++;
}
cout << "\n操作1のob.end()が指していた値: " << *p << "\n\n";
return 0;
}
|
実行結果
| 9 8 7 6 5 4 3 2 1 0 ------------------------------------------- endは両端キューの最後の要素の次の要素を指す反復子を返す 操作1 0 1 2 3 4 5 6 7 8 9 -842150451 ob.end()が指す値: -842150451 操作2 0 1 2 3 4 5 6 7 8 9 0 -842150451 操作1のob.end()が指していた値: 0 |
-842150451は処理系のよって値が変わるか・・・コンパイルエラーになるか・・・