Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // typedefs to make our lives easier :D
- typedef std::map<unmanaged_cli_ptr<System::String>*, unmanaged_cli_ptr<System::String>*> MyMapType;
- typedef std::pair<unmanaged_cli_ptr<System::String>*, unmanaged_cli_ptr<System::String>*> MyMapPairType;
- // finds a value corresponding to key from std::map
- unmanaged_cli_ptr<System::String>& FindString(const MyMapType& map, unmanaged_cli_ptr<System::String>* key)
- {
- for (MyMapType::const_iterator begin = map.begin() ; begin != map.end() ; begin++)
- {
- if (System::String::Compare(**begin->first, **key) == 0)
- {
- return *begin->second;
- }
- }
- throw std::exception("cant find key");
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- // create a map and insert one item
- MyMapType myMapOfStrings;
- // insert
- System::String^ myEntryKey = "this is a key of map item";
- System::String^ myEntryValue = "this is value corresponding to key";
- myMapOfStrings.insert(MyMapPairType(new unmanaged_cli_ptr<System::String>(myEntryKey),
- new unmanaged_cli_ptr<System::String>(myEntryValue)));
- // find that item and print the value
- System::String^ searchForKey = "this is a key of map item";
- System::Console::WriteLine(*FindString(myMapOfStrings, &unmanaged_cli_ptr<System::String>(searchForKey)));
- std::cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment