Linked Questions
14 questions linked to/from How do you loop through a std::map?
-1
votes
2
answers
2k
views
How to iterate map<int, vector <int>>? [duplicate]
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 C++ map of maps?
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["...
117
votes
5
answers
87k
views
How to choose between map and unordered_map?
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
what does `auto const& x ` do in C++?
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)
<...
1
vote
1
answer
8k
views
Get the previous or next item in a map from a for loop
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
C++ creating a map with a string as key and vector of string as value [closed]
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 ...
3
votes
3
answers
612
views
Why this is an infinite loop
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....
2
votes
2
answers
2k
views
Create a template to iterate map in C++11 like C++17's structured bindings
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 ...
2
votes
3
answers
180
views
Is there a way to calculate lcm of at most 30 numbers with each number being largest at 10^6?
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
How to endlessly loop over map
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&...
-2
votes
1
answer
294
views
Compiler error while compiling C++17 for loop on a map
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 { ...
-3
votes
1
answer
140
views
loop over map of vectors and get max across columns in c++
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 ...
0
votes
2
answers
99
views
When I loop through a C++ map, why does it give me an instantiation error?
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;
...
0
votes
2
answers
97
views
Class destructor to delete other class
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 ...