STL容器の簡単な使い方まとめ


**  set
≪プロパティ|Properties|oraolap≫:要素の繰返しは許可されず、要素のディクショナリの順序付けは許可されず、下付きオペレータは提供されません.
宣言:seta;
挿入:a.insert(b);
遍歴:
set<int>::iterator a_it;//       
for (a_it = a.begin(); a_it != a.end(); a_it++)
cout << *a_it;

空かどうかを判断する:a.empty();
要素の数:a.size();
削除:a.erase(b);//b+1番目の要素を削除
クリア:a.clear()
要素の取得:
a_it=a.find(b);
cout<<*a_it;//*a_itはb+1番目の要素を返します
a.count(b)b+1番目の要素が存在するか
 
**  map
プロパティ:関連配列、キーインデックス辞書の順序付け、キーインデックスの重複は許可されず、後で挿入されると前のものが上書きされます.
宣言:mapa;//キーインデックスstringクラス、関連値int型
挿入:a[b]=c;//bはstringクラス、cはint型
遍歴:
map<string, int>::iterator a_it;
for (a_it = a.begin(); a_it != a.end(); a_it++)
cout << a_it->first << " " << a_it->second << endl;//first    

空かどうかを判断する:a.empty();
要素の数:a.size();
削除:
a.erase(b)/bはstringクラス、削除キーインデックスbの要素
a.erase(a_it)/反復器a_の削除itが指す要素
A.erase(a_it 1,a_it 2)//一部削除
クリア:a.clear()
要素の取得:
a_it = a.find(b);//キーインデックスをbとして探し、その要素を指す反復値を返す
cout << a_it->first << " " << a_it->second << endl;
a.count(b)/キーインデックスbの要素が存在するかどうか
 
** string
getlineでテキスト全体を読み込む
string line;
while (getline(cin, line))
cout << line << endl;

操作:line.empty();line.size();line[n];
 
** stack
属性:スタック、先頭後出
宣言:stacka;
操作:
a.empty();
a.size();
a.pop();
a.top();
a.push(item);
 
** queue
プロパティ:キュー、先頭に移動
宣言:queuea;
操作:
a.empty();
a.size();
a.pop();
A.top();//優先順位のある要素
a.front();//キューヘッダに戻る
a.back();//キューの最後の要素を返します
a.push(item);