map ¶
- dictionary ꡬ쑰λ₯Ό ꡬννμλ€. DataStructure μμλ symbol table μ΄λΌκ³ λ§νλ€.
- dictionary ꡬ쑰λ key μ valueκ° μ‘΄μ¬νλ©°, keyλ₯Ό μ΄μ©νμ¬ valueλ₯Ό μ°Ύλ μλ£κ΅¬μ‘°μ΄λ€.
- μ΄ κ΅¬μ‘°λ κ° μΈμ΄λ§λ€ λ€μν μ΄λ¦μ κ°μ§λ€.
Perl, PHP Associated Array Python dictionary Java ~cpp HashMap, Hashtable
STL(C++) map - include : map
~cpp #include <map>
μ μΈ ¶
~cpp // map<key_type, value_type> map<string, long> m;
key λ£κΈ° ¶
~cpp m["νκΈΈλ"] = 20;
μν ¶
~cpp // for μμ λ°λ³΅μ μ΄μ© μν for(map<int, int>::iterator i; i = m.begin() ; i != m.end() ; ++i) { cout << "key: " << (*i).first << "value: " << (*i).second << endl; }
νλ‘κ·Έλ¨μ μ ¶
~cpp #include <iostream> #include <map> #include <string> using namespace std; int main() { map<string, long> directory; directory["νκΈΈλ"] = 1234567l; directory["κΉμ² μ"] = 9876543l; directory["κΉλ΄λ¨"] = 3459876l; cout << "μ ν λ²νΈλΆμ λ΄μ©μ " <<endl; map<string, long>::iterator i; i = directory.begin(); for ( ; i != directory.end();i++) cout << "μ΄λ¦:" << (*i).first << " μ νλ²νΈ: " << (*i).second << endl; cout << "μ λλ€. "<<endl; string name; while( cin >> name ){ if ( name.compare("exit") ==0)break; cout << "μ΄λ¦μ μ λ ₯ν΄ μ£ΌμΈμ.(μ’ λ£:exit):"; if (directory.find(name) != directory.end()) cout << name << "μ μ νλ²νΈλ" << directory[name] << "μ λλ€.n"; else cout << "μ£μ‘ν©λλ€. κ·Έ μ΄λ¦μ΄ μ ν λ²νΈλΆμ μμ΅λλ€." << name << "n"; } return 0; }
Thread ¶
μμ¬μ΄μ : VC++ 6.0 μμ map νλ² μ°λ©΄ warning μ΄ 72κ°κ° λ¬λ€; STLPort λ₯Ό μ¨μΌ ν κΉ..
----
STL
warning μ μ΄μ λ STLμμ λμ€λ λλ²κ·Έμ μ λ³΄κ° VC++ λλ²κ·Έ μ 보λ₯Ό μν΄ ν λΉνλ 곡κ°(255byte)λ³΄λ€ λ§κΈ° λλ¬Έμ
λλ€. λ³΄ν΅ λλ²κ·Έ λͺ¨λλ‘ λλ²κΉ
μ νμ§ μμΌλ©΄, Project settingμμ C/C++ ν
μμ Debug info λ₯Ό μ΅μν line number only λ‘ ν΄λμΌλ©΄ warning λ μμ΄ μ§λλ€. κ·Έλλ warning κ° λλ€λ©΄ C/C++ ν
μμ Generate browse info λ₯Ό λΉνμ±(κΈ°λ³Έκ°)ν μν€μΈμ.
# pragma warning( disable : 4786 ) νμλ©΄ λ©λλ€.
----
STL