As in c we can use various format specifiers like
- %nd where n is a number, to print the number with a total of atleast n space covered
- %0nd same as above, except pre-padding with 0's " %05d ",3 => 00003
- %.nf to set precision of n after decimal
- etc ....
So is there any way to use these with std::cout ?
I got some negative feedback in a recent course (c++ for c programmers) in coursera, for using printf instead of cout because i wanted to some formatting :(
For
%nd%0nd, C++ equivalents arestd::setw()andstd::setfill().Output:
xxxxxxxx77%.nfcan be replaced bystd::setprecisionandstd::fixed,Output: