Aug 8, 2011 at 1:29am UTC
hello
I have a map<string, int>
and i need to right it so the list is perfect, same width betwin name and numbers on every line.
The code:
for(map<string, int>::const_iterator it = kottvaror.begin(); it != kottvaror.end(); it++)
{
cout << it->first << setw(6) << it->second << endl;
}
The output Now:
annie 6
jax 3
Karthus 5
Tryndamere 8
Gangplank 4
Xinchao 9
Mordekaiser 8
They way I want it to be;
annie--------6
jax----------3
Karthus-----5
Tryndamere--8
Gangplank---4
Xinchao------9
Mordekaiser--8
so Note! that every "-" is a Space i just culdnt make it a space cuz it wouldnt work in this forum system,, or i dont know how to .
im getting crazy i have tried every thing i know.. cant make it work plz help!!
Aug 8, 2011 at 2:19am UTC
Use setw() to set the width of the first column too! Iterate through the items to find out the max length, then use that as the width of the first column, and then use setw() again for the second column.