STL

STLで正規表現

※OLE2T が実行されるたびに、スタック領域が消費されるのでループ内での使用や、非常に大きな文字列の使用は避けてね! #include <regex> #include <string> #include <iostream> ..... // パーサー LPTSTR p_json = OLE2T(json); // strtok "}"で区切り LPTSTR p_tp; LPTSTR p_next; </iostream></string></regex>…

Visual C++ 2010に追加されたSTLアルゴリズム

サンプルコードがあってわかりやすい。 none_of, any_of, all_of find_if_not copy_if, copy_n partition_copy, is_partitioned, partition_point is_sorted, is_sorted_until is_heap, is_heap_until iotahttp://codezine.jp/article/detail/5206

vectorのソート

std:sort()を使う #include <vector> #include <algorithm> using namespace std; ・・・ vector<long> data; data.push_back(10); data.push_back(5); sort(data.begin(),data.end());//昇順ソートネタ元 http://7ujm.net/stl/sort.html</long></algorithm></vector>

vectorでの検索(find)の仕方

vector自体にはfindがないのでアルゴリズムを使う vector<long> v_list; ・・・ v_list.push_back(100); v_list.push_back(200); v_list.push_back(300); vector< long >::iterator cIter = find( v_list.begin(),v_list.end() , 200 ); if( cIter != v_list.end() ){</long>…

map<>で存在しないキー判定

find()で調べる。 // キーと値が が string と string なマップを生成 map<string, string> itemMap; // マップに値を挿入 itemMap.insert(pair<string, string>("hoge", "ほげ")); itemMap.insert(pair<string, string>("foo", "ふー")); if( itemMap.end() != itemMap.find("foo") ){ // 発見 }else{ // 見</string,></string,></string,>…