#Problem with maps..
21 messages · Page 1 of 1 (latest)
why not do j->second()?
. has higher precedence than * iirc
so its doing *(j.second) isntead of (*j).second
u can also use a range based loop
this should work too ```cpp
for (auto a : str)
m[a]++;
for (auto a : m)
{
p += a,second / 2;
solo += a.second % 2;
}
(also should be j->second, since you're trying to access a data member of a pair)
well, a.second there, iterating over a map gives you pairs
fixed
👍
u can even do ```cpp
for (auto [k, v] : m)
{
p += v / 2;
solo += v % 2;
}
wait lmao do u actually use 3 spaces indentation
Thanks!
I forgot it exists
Wait, so k is first, v is second?
This is so much better than regular, not range based loop!
ye
well it is a range-for loop, it's mostly that along with it he used another feature from c++17 called "structured bindings"
those can be used outside of loop syntax
and can be quite handy to get all elements in a pair/tuple/tuple-like
@wispy roost
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.