bryce1010-ACM-Template icon indicating copy to clipboard operation
bryce1010-ACM-Template copied to clipboard

STL

Open Bryce1010 opened this issue 5 years ago • 1 comments

Bryce1010 avatar Apr 22 '20 07:04 Bryce1010

unordered_map [reference]

#include <iostream>
#include <string>
#include <unordered_map>
 
int main()
{
    // Create an unordered_map of three strings (that map to strings)
    std::unordered_map<std::string, std::string> u = {
        {"RED","#FF0000"},
        {"GREEN","#00FF00"},
        {"BLUE","#0000FF"}
    };
 
    // Iterate and print keys and values of unordered_map
    for( const auto& n : u ) {
        std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n";
    }
 
    // Add two new entries to the unordered_map
    u["BLACK"] = "#000000";
    u["WHITE"] = "#FFFFFF";
 
    // Output values by key
    std::cout << "The HEX of color RED is:[" << u["RED"] << "]\n";
    std::cout << "The HEX of color BLACK is:[" << u["BLACK"] << "]\n";
 
    return 0;
}

Bryce1010 avatar Apr 22 '20 07:04 Bryce1010