Output date display problem in C + + (do not use printf): Programming questions #4:tomorrow never knows?

Source: Internet
Author: User

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&LT;&LT;SETW (4) <<year<<"-";//Set the output character width to 4, and then output "-" theCOUT&LT;&LT;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<<"-"&LT;&LT;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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.