Created
June 22, 2010 11:03
-
-
Save pcyu16/448333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <map> | |
| #include <string> | |
| using namespace std; | |
| map<string,int> table; | |
| void print() | |
| { | |
| map<string,int>::iterator it; | |
| cout << "table contents:" << endl; | |
| for(it=table.begin();it!=table.end();it++) | |
| cout << "name: " << it->first << ", val:" << it->second << endl; | |
| } | |
| int main() | |
| { | |
| int cnt=0, times; | |
| string str; | |
| table.clear(); | |
| // insert | |
| times=2; | |
| while(times--){ | |
| cout << "input id >> "; | |
| cin >> str; | |
| table[str] = ++cnt; | |
| } | |
| print(); | |
| // query | |
| cout << endl; | |
| times = 2; | |
| while(times--){ | |
| cout << "query >> "; | |
| cin >> str; | |
| if( table.find(str) != table.end() ) | |
| cout << "found: " << str << ' ' << table[str] << endl; | |
| else | |
| cout << "cannot find " << str << endl; | |
| } | |
| // delete | |
| cout << endl; | |
| cout << "delete >> "; | |
| cin >> str; | |
| table.erase(str); | |
| print(); | |
| table.clear(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment