Answer the question
In order to leave comments, you need to log in
How to use the setw manipulator in c++?
I started learning c++ using R. Laforet's book.
The book gives an example of using this manipulator:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long pop1=8425785, pop2=47, pop3=9761;
cout << setw(9) << "Город " << setw(12) << "Население " << endl
<< setw(9) << "Москва" << setw(12) << pop1 << endl
<< setw(9) << "Киров" << setw(12) << pop2 << endl
<< setw(9) << "Угрюмовка" << setw(12) << pop3 << endl;
return 0;
}
Город Население
Москва 8425785
Киров 47
Угрюмовка 9761
Город Население
Москва 8425785
Киров 47
Угрюмовка 9761
Program ended with exit code: 0
Answer the question
In order to leave comments, you need to log in
Try:
cout << setw(9) << "City" << setw(12) << "Population" << endl
<< setw(9) << "Moscow" << setw(12) << right << pop1 << endl
<< setw(9) << "Kirov" << setw(12) << right << pop2 << endl
<< setw(9) << "Glum" << setw(12) << right << pop3 << endl;
Good afternoon. I also started to learn c++ from R. Laforet's book, and this problem also appeared.
Everything turned out to be trite. It's just that Xcode and other compilers do not work correctly with Cyrillic, so such shifts are obtained. If everything is in Latin, then there will be right alignment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question