Vote count:
0
I'm using setw() to do input formatting in my program. I understand that the way this functions is that it creates a certain amount of spaces based on the parameter, but these spaces will be filled by anything in the output stream. Otherwise, it will create only blank spaces.
For example, using setw(5):
cout << setw(5) << "hi";
Will output:
...hi
where periods are equivalent to blank spaces. However, my current issue performs like so:
cout << setw(5) << "hi";
Will output:
.....hi
The current issue is that it will set the width to five spaces, but it will push anything in the output stream past the reserved spaces. I have tried diagnosing the issue by changing where I set the width, but I realized that it is a fruitless effort because it needs to be placed in front of the output stream to set the width for that output.
Any suggestions?
setw(x) creates x spaces, but pushes given characters past the reserved spaces?
Aucun commentaire:
Enregistrer un commentaire