Answers for "c++ mapping"

C++
9

map c++

#include <iostream>
#include <string>
#include <map>

using std::string;
using std::map;

int main() {
	// A new map
  	map<string, int> myMap = { // This equals sign is optional
		{"one", 1},
    	{"two", 2},
    	{"three", 3}
  	};

  	// Print map contents with a range-based for loop
    // (works in C++11 or higher)
  	for (auto& iter: myMap) {
    	std::cout << iter.first << ": " << iter.second << std::endl;  
  	}
}
Posted by: Guest on August-22-2020
1

map in c

#include <map>

std::map<size_t, std::string> map;

map[10] = "Hello";
map[1] = "boys";
map[901] = "girls"
Posted by: Guest on October-06-2020

Browse Popular Code Answers by Language