Linked Questions

14 questions linked to/from How do you loop through a std::map?
-1 votes
2 answers
2k views

I have map<int, vector > like this: #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<int, vector <int>> someMap;...
301 votes
9 answers
452k views

How can I loop through a std::map in C++? My map is defined as: std::map< std::string, std::map<std::string, std::string> > For example, the above container holds data like this: m["...
Jack's user avatar
  • 3,819
117 votes
5 answers
87k views

Suppose I wanted to map data with a string as the key. What container should I have chosen, map or unordered_map? unordered_map takes up more memory so let's suppose memory isn't an issue, and the ...
1 vote
1 answer
3k views

I'm reading the accepted answer to this question C++ Loop through Map An example in that answer: for (auto const& x : symbolTable) { std::cout << x.first // string (key) <...
haruhi's user avatar
  • 197
1 vote
1 answer
8k views

I'm making a calculator that can accept more than one operator at once (e.g. 5x5x5). I have a map that contains the positions of the operators, and what type they are (x/+-). I also have a for loop ...
-5 votes
2 answers
4k views

This code prompts the user asking their name and the school they attend. Storing both into a map(the names into vector). I then want to print out the school and the name of every person that attended ...
Msarn21's user avatar
  • 11
3 votes
3 answers
612 views

i have declared a map below using stl and inserted some values in it. #include<bits/stdc++.h> int main() { map<int,int> m; m[1]=1; m[2]=1; m[3]=1; m[4]=1; m[5]=1; m[6]=1; for(auto it=m....
Simple being's user avatar
2 votes
2 answers
2k views

C++17 brought us a nicer way to iterate through map using the Structured binding, as shown in this example . I am bound to use C++14 but have a lot of repeating code that iterates over maps. In C++14 ...
joepol's user avatar
  • 852
2 votes
3 answers
180 views

I'm using C++ for this. The problem is that the answer can't be a long long, because the number is gigantically big, like 10^50. With this type of problem, I really can't think of any solutions. If ...
0 votes
1 answer
309 views

I need to iterate over the entire map without stopping the loop. My example works but it uses two loops, can this be fixed? I think it's possible to do this using only one for loop #include <map&...
menfix's user avatar
  • 61
-2 votes
1 answer
294 views

I used to compile the following code: const std::map<std::string, bool> pending_achs = The result from this method std::map<std::string, bool> get_pending_ach_modifications() const { ...
yhu420's user avatar
  • 637
-3 votes
1 answer
140 views

I have a map defined as follows: const map<int, vector<float> >& m = ...; I want to loop over the columns (size of the map.second: vector) and in every iteration I get the: 1- The max ...
AhmedTE's user avatar
  • 21
0 votes
2 answers
99 views

I am trying to loop through a map but nothing I try seems to work... I declare and define the map as follows: // loop through the strings and group based on length map<size_t, NGroup> groups; ...
joshua's user avatar
  • 487
0 votes
2 answers
97 views

I need help creating a class destructor. I don't really understand how to create one but I do understand what they do. Since new is called to create users and prizes, I need to write a destructor ...