peter_CGY 2022-05-31 17:35 采纳率: 75%
浏览 20
已结题

想要计算从2012年1月22日到某一天过了多少天

想要计算从2012年1月22日到某一天过了多少天但最后说cout有问题,我看不懂,是跟左值右值有关系吗,为什么。

###### #include<iostream>
using namespace std;
int monthDays[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31};//每个月的天数
int main()
{
    int year,month,day,days;
     day =0;
    cin>>year>>month>>day;
    //从2012年每过一年的天数
    for(int y=2012;y<=year;y++){
        if(y%4==0&&y%100!=0||y%400==0)
        days+=366;
        else 
        days+=365;
    }
    //从1月每过一个月的天数
    if(year%4==0&&year%100!=0||year%400==0)
        monthDays[2]=29;
        for(int m=1;m   <month;m++)
        days+=monthDays[m];
        //当日是在22号的前面还是后面
    int d=22;
    if (d<day)
    days=days+day-d;
    else
    days=days-22;

    
    cout>>days>>endl;
    return 0;
         
}

######29 6 C:\Users\Peter\Documents\计算?絰x年?x月xx日需??少??cpp [Error] no match for 'operator>>' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'int')
980 5 D:\DEV C++\Dev-Cpp\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\9.2.0\include\c++\istream [Error] no type named 'type' in 'struct std::enable_if<false, void>'

我的解答思路和尝试过的方法
成功运行程序。
  • 写回答

2条回答 默认 最新

  • 不会长胖的斜杠 新星创作者: 后端开发技术领域 2022-05-31 17:46
    关注

    cout>>days>>endl;
    修改为
    cout<<days<<endl;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月8日
  • 已采纳回答 5月31日
  • 创建了问题 5月31日