Answers for "std map"

C++
2

c++ map iterator

#include <iostream>
#include <map>
 
int main() {
  std::map<int, float> num_map;
  // calls a_map.begin() and a_map.end()
  for (auto it = num_map.begin(); it != num_map.end(); ++it) {
    std::cout << it->first << ", " << it->second << 'n';
  }
}
Posted by: Guest on March-08-2020
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
0

map in cpp

#include <map>

int main(){
  //new map
  std::map <int,int> myMap;
  myMap[0] = 1;
  myMap[1] = 2;
  myMap[2] = 3;
  myMap[3] = 4;
}
Posted by: Guest on November-11-2020

Browse Popular Code Answers by Language