C++ STL 標準ライブラリ イテレータ 繰り返し サンプルメ[ス iterator
■イテレータの使い方。 -- サンプルメ[ス #include <list> #include <iostream> int main() { using namespace std; list<int> nums; // front_inserter によるインサート front_inserter(nums) = 30; // 先頭に30を挿入 front_inserter(nums) = 20; // 先頭に20を挿入 front_inserter(nums) = 10; // 先頭に10を挿入 // back_inserter によるインサート back_inserter(nums) = 40; // 末尾に40を挿入 back_inserter(nums) = 50; // 末尾に50を挿入 back_inserter(nums) = 60; // 末尾に60を挿入 // listの内容を出力 list<int>::iterator itr = nums.begin(); while(itr != nums.end()) { cout << *itr << endl; ++itr; } return 0; } -- 出力結果 10 20 30 40 50 60
http://goodjob.boy.jp/chirashinoura/id/95.html
作成日: 2006-08-31 15:35:55
最終更新日: 2006-08-31 15:37:38
▲このページの上へ管理人: ぶらざーほわいつ 連絡