+ 2
Date formatting?
https://code.sololearn.com/c454ZOctiB5J/?ref=app How can I format the date like "02/09/1998"? Getting an error when I try it.
4 Antworten
+ 3
#include <iomanip>
std::cout << std::setw( 2 ) << std::setfill( '0' ) << 2;
+ 1
//Try this one it works
cout <<'0'<<month << '/' << '0'<<day << '/' << year << "\n\n";
+ 1
Wouldn't both of those add a zero even if the number is over 9?
+ 1
My solution wouldn't.
setw kinda creates an 'array', for ease of explanation, of width 2 in this case.
[ . . ]
setfill fills em with '0' in this case
[ '0' '0' ]
Whatever you put into the stream after that overwrites whatever is in that array from the right
<< 2
[ '0' '2' ]
If I did << 21 the array would become
[ '2' '1' ]
No zeros there.