Return to Tech/cpluplu

C/C++ Programming - STL

About STL
STLとは
STL(Standard Template Library)はlist, vectorと
いったjavaや.NET系言語でおなじみの機能を提供する
便利なライブラリです。
list, iteratorの利用例
int main(void) {
  // 名前一覧を格納する入れ物を用意
  list names;

  // 上記の入れ物に名前を追加(後ろに追加)
  names.push_back("name001");
  names.push_back("name002");
  names.push_back("name003");

  // イテレータを用いて名前一覧の入れ物にアクセスします
  // デザインパターンの例のひとつ
  list::iterator it = names.begin();

  for( ; it != names.end(); it++ ) {
    cout << it->data() << endl;
  }
}
実行結果例:
name01
name02
name03

Return to Tech/cpluplu