2013-03-06から1日間の記事一覧

STL スタック

STL std::stack #include <stack> #include <iostream> #include <vector> //後入れ先だし コンストラクタにより、空の状態で初期化される。 void test1() { std::stack<int> st; st.push(10); st.push(20); std::cout<<st.top()<<std::endl; st.pop(); } void test2() { std::stack<int, std::vector<int> > st; st.push(10); st.push(20); st.pop(); st…</st.top()<<std::endl;></int></vector></iostream></stack>

スタック

C++

//一番最後に格納したデータが取り出される. //後入れ先出し(Last In First Out)という LIFO //例 机に積み重ねられた本 積む:push 降ろす:pop //スタックを実現するには、配列中のどの位置までは使われているのかを管理する必要があります。 //この位置を管…

テンプレート

C++

テンプレート //コンパイル時にテンプレート型Tの部分が、適切な型に置き換えられます。 #include <iostream> template <class T> class CSample { public: CSample(const T& t) : t_(t){} private: T t_; };</class></iostream>

std::mapの使い方

C++

std::map< 型, 型> tbl; 型が2つ指定できるので、keyとvalueの型を自由に変更できる。 std::map<std::string, int> tbl1; tbl1["hoge"] = 0; std::map<int, std::string> tbl2; tbl2[100] = "hoge"; ↓ソース #include <iostream> #include <string> #include <map> #define msg(a) std::cout<</map></string></iostream></int,></std::string,>