Possible Duplicate:
C++ alignment when printing cout <<
I am writing a set of words in an output file . I have left three tabspaces using ‘\t’ character between the words . But at times when the words are too small or too large there seems to be a problem with the alignment. How to give a constant space between words which would work even when the words are small ?
Here’s what i am talking about.
Word:elpmas Count:1
Word:This Count:4
Word:pmasel Count:1
Word:is Count:1
Word:sample Count:1
Word:sentence Count:1
Word:si Count:1
Word:a Count:1
I want to have a constant space between the words and the counts. I currently use
cout<< "Word:"<< hash->key <<"\t\t\t" << "Count:" << hash->value <<endl;
Help me out.
The setw stream manipulator is useful for aligning columns in tabular output. For instance,
Will properly align your output provided that your keys are at most 15 characters.