Because you can not use the printf function, but also cry, good, directly explain the idea: the topic said can be used Setfill and SETW control, that should be able to solve the problem:
Direct Sticker Code:
1#include <iostream>2#include <stdio.h>3#include <iomanip>4#include <string.h>5 using namespacestd;6 BOOLIsleapyear (intYear ) {7 BOOLIsleap =false;8 if(Year% -==0)|| (Year%4==0&& Year% -!=0))9Isleap =true;Ten returnisleap; One } A - intMain () { - intYear , month, day; thescanf"%d-%d-%d", &year, &month, &Day ); - - intmonth_data[ A] = { to, -, to, -, to, -, to, to, -, to, -, to}; - + if(Day >= month_data[month-1]){ - if(Month = = A ){ +year++; Amonth =1; atDay =1; - } - Else if(Month = =2 ){ - if(Isleapyear (year) && day = = -) -Day = in; - Else{ inmonth++; -Day =1; to } + } - Else{ themonth++; *Day =1; $ }Panax Notoginseng - } the Else +day++; ACOUT<<SETW (4) <<year<<"-";//Set the output character width to 4, and then output "-" theCOUT<<SETW (2) <<setfill ('0') <<month;//here Set the output character width to 2, if the number of characters is not enough, 0 will be added +cout<<"-"<<SETW (2) <<setfill ('0') <<day<<endl;//here first print "-", and then output character width of 2, insufficient to be supplemented by 0. - return 0; $ $}
No Baidu to solve the method, I am also considered original.
Output date display problem in C + + (do not use printf): Programming questions #4:tomorrow never knows?