Answers for "c++ map to vector"

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
0

how to copy elements from hash to vector c++

/* make sure that the vector can include the element in the map
*/

#include <vector>
#include <map>
using namespace std;

int main(){
    map<int, vector<vector<int>> hash;
  	vector<vector<vector<int>>> putTo;
  	map<int, vector<vector<int>>::iterator it;
  	
  	for(it = hash.begin(); it != hash.end(); it++){
      	// notice if the putTo was a 2D we can add it->second to it;
      	// it have to be 3D in order to hold a 2D array
    	putTo.push_back(it->second);  
    }
	return 0;
}
Posted by: Guest on August-17-2020

Browse Popular Code Answers by Language