yo/containers/examples/mapfind.cc
raw| 1 | #include <iostream> |
| 2 | #include <map> |
| 3 | using namespace std; |
| 4 | |
| 5 | int main() |
| 6 | { |
| 7 | map<string, int> object; |
| 8 | |
| 9 | object["one"] = 1; |
| 10 | |
| 11 | map<string, int>::iterator it = object.find("one"); |
| 12 | |
| 13 | cout << "`one' " << |
| 14 | (it == object.end() ? "not " : "") << "found\n"; |
| 15 | |
| 16 | it = object.find("three"); |
| 17 | |
| 18 | cout << "`three' " << |
| 19 | (it == object.end() ? "not " : "") << "found\n"; |
| 20 | } |
| 21 | /* |
| 22 | Generated output: |
| 23 | `one' found |
| 24 | `three' not found |
| 25 | */ |