we are doing ans.pushback() then how it is getting printed in next line
How the output of this code is getting printed in next line.please explain me the code
@Prabhleen_sheenu ans is a 2D vector, you are not printing anything, just for sake of visible convenience, they are shown in different line!
yes its a 2d vector but how it gets to know that what is in second row?
you can simply iterate this way
for(int i=0;i<ans.size();i++)
{
for(int j=0;j<ans[i].size();j++)
cout<<ans[i][j]<<" ";
cout<<endl;
}
yea sir… my doubt is without writing these lines(2 for loops) usme kaise horha yeh
for(auto it=m.begin();it!=m.end();it++)
{
ans.push_back(it->second);
}
or jaise apne cout k liye 2 for loops se kiya hai pushback kaise kr skte hain 2 for loops se
here it->second is a vector of string, so you are pushing vector in a vector of vectors, which is valid
Also this can also be done using 2 for loops!(but do it directly)
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.
