please tell the error
the
for(auto i:m)
{
cout<<i.first<<"–>"<<i.second<<endl;
}
why this loop is not working?
Map stl code doubt
unordered_map<string,vector> m;
since the value type is string
so u need to iterate over the vector
for(auto i:m)
{
cout<<i.first<<"–>";
for(string s : i.second)
cout << s <<" ";
}
so for map<int,vector> > m …then we don’t need to itertate the vector…right?
we are iterating the vector here
ma’am i have a doubt
for(auto pp:m)
{
v.push_back(pp.second);
}
according to my input
My input is
6
eat ate tan bat tan nat
the map my created is like this:
abt–>bat
aet–>eat tea ate
ant–>tan nat
I know ma’am my map will be like this…so how this above second part of map is inserted into the vector according to above loop?..like how this just single loop has inverted m[0].second as vector[0] and m[1].second as vector[1] and m[2].second as vector[2]…?/how this in just one loop?
see
m[any index] .second is a vector
and also
vector<vector> v;
is a 2 d vector
so v meh push_back hum m[s2].second { which is a vector is getting added }
like vo pura vector he add ho raha h
yeh nhi ho rha
exactly yeh nhi ho raha
puri vector dul rahi h
try doing it with for to better samjh ayega kaise ho raha h
yaa okay ma’am!..
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.