Advertisement
obernardovieira

Alloc Variables (unordered_map)

Sep 27th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <tuple>
  3. #include <queue>
  4. #include <unordered_map>
  5.  
  6. typedef std::unordered_map<int, std::tuple <int, char> > IndexMap;
  7. IndexMap indexMap;
  8.  
  9. int main () {
  10.     int myint;
  11.     char mychar;
  12.  
  13.     indexMap[0] = std::make_tuple(5,'l');
  14.     indexMap[1] = std::make_tuple(50,'z');
  15.     indexMap[2] = std::make_tuple(30,'g');
  16.  
  17.     for(int v = 0; v != 5; v++) {
  18.         IndexMap::iterator k = indexMap.find(v);
  19.         if(v == 1) {
  20.             indexMap.erase(k);
  21.             std::cout << "Vazio" << std::endl;
  22.             continue;
  23.         }
  24.         if ( k != indexMap.end() ) {
  25.             std::tie (myint, mychar) = indexMap[v];//std::ignore
  26.             std::cout << "myint : " << myint << '\n';
  27.             std::cout << "mychar : " << mychar << '\n';
  28.         }
  29.         else {
  30.             std::cout << "Vazio" << std::endl;
  31.         }
  32.     }
  33.  
  34.     system("pause");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement