Format control in C++

There are many format controls in C++. We will only talk about the most commonly used ones here (setting field width, padding, left alignment).

1 Domain width setting:

Header file: #include<iomanip>

Function: setw (the domain width you want is int n, n positions)

For example

 cout<<setw(10)<<0;;

Effect: *********0 (*can be the data you output)

2 Filling (to be used in conjunction with setw)

Header file: #include<iomanip>

setfill(char c);

cout<<setw(10)<<setfill('0')<<1;

Effect: 0000000001;

3 Left-aligned (the system generally defaults to right-aligned)

Header file: #include<iomanip>

setiosflags(ios::left)    

cout<<setw(10)<<setfill('0')<<setiosflags(ios::left) <<1;

Effect: 1000000000;

If my article is helpful to you, then please do it three times and refuse free prostitution.

Guess you like

Origin blog.csdn.net/m0_74316391/article/details/129913874