Three quick ideas for C++ code

#include <iostream> #include <vector> #include <tuple> #include <iomanip> using namespace std; int main() { vector<tuple<string, int>> cities = { {"Brussels", 1019022}, {"Antwerpen", 459805}, {"Gent", 231493}, {"Charleroi", 200132}, {"Liege", 182597}, {"Brugge", 116709}, {"Namur", 106284}, {"Leuven", 92892}, {"Mons", 91277}, {"Aalst", 77534}, {"Mechelen", 77530}, {"La Louviere", 76668}, {"Kortrijk", 73879}, {"Hasselt", 69222}, {"Ostend", 69011} }; // Unpacking tuples (without the tie function) cout << "Cities in Belgium: " << endl; for(auto [city, population] : cities) { cout << city << " has a population of " << population << "." << endl; } /* Cities in Belgium: Brussels has a population of 1019022. Antwerpen has a population of 459805. Gent has a population of 231493. Charleroi has a population of 200132. Liege has a population of 182597. Brugge has a population of 116709. Namur has a population of 106284. Leuven has a population of 92892. Mons has a population of 91277. Aalst has a population of 77534. Mechelen has a population of 77530. La Louviere has a population of 76668. Kortrijk has a population of 73879. Hasselt has a population of 69222. Ostend has a population of 69011. */ // Tab-like formatting cout << "Populations of some cities in Belgium:" << endl; int i = 1, cols = 5; for(auto [city, population] : cities) { cout << setw(10) << setfill(' ') << setprecision(8) << population << ((i % cols != 0) ? " " : "\n"); i++; } /* Populations of some cities in Belgium: 1019022 459805 231493 200132 182597 116709 106284 92892 91277 77534 77530 76668 73879 69222 69011 */ // Boolean values as string (using the tie function) string city; int population; int threshold = 100000; for(tuple<string, int> city_data : cities) { tie(city, population) = city_data; cout << city << " has more than " << threshold << " citizens: " << boolalpha << (population > threshold) << endl; } /* Brussels has more than 100000 citizens: true Antwerpen has more than 100000 citizens: true Gent has more than 100000 citizens: true Charleroi has more than 100000 citizens: true Liege has more than 100000 citizens: true Brugge has more than 100000 citizens: true Namur has more than 100000 citizens: true Leuven has more than 100000 citizens: false Mons has more than 100000 citizens: false Aalst has more than 100000 citizens: false Mechelen has more than 100000 citizens: false La Louviere has more than 100000 citizens: false Kortrijk has more than 100000 citizens: false Hasselt has more than 100000 citizens: false Ostend has more than 100000 citizens: false */ return 0; }