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