How to create an abbreviation with using in C++

1 Answer

0 votes
#include <iostream>
#include <map>
#include <string>

// Abbreviation: using creates a modern type alias.
using PhoneBook = std::map<std::string, std::string>;

int main() {
    PhoneBook pb;  // Using the abbreviation

    pb["Jack"] = "123-456";
    pb["Luna"] = "987-654";

    for (const auto& entry : pb) {
        std::cout << entry.first << ": " << entry.second << "\n";
    }
}



/*
run:

Jack: 123-456
Luna: 987-654

*/

 



answered 1 day ago by avibootz
...