首页 > 解决方案 > 我想更正我的程序并使其按预期显示初始时间

问题描述

我正在尝试编写一个将时间设置为 2018 年 11 月 7 日的编程,但它不起作用。它只显示 4 个错误。有人可以帮我纠正代码。

#include <iostream>
using namespace std;

class date {
private: 
    int day,month,year;

public:
    void advance();

    date(){
        day=1;
        month=1;
        year=2018;
    };

    void setDate(){
        cout<<day<<"/"<<month<<"/"<<year<<endl;
    }
};

void date::advance(){
    for(month=1;month=<12;month++){
        for(day=1;day=<31;day++){
            cout<<day<<"/"<<month<<"/"<<year<<endl;
        }   
    }
}

int main(){
    date d;
    cout<<"Date set as:";
    d.setDate();
    cout<<"Setting the advance method"<<endl;
    d.advance();
    return 0;
}

它显示在成员函数中void date::setDate()

[Error] expected primary-expression before '<<' token
In member function 'void date::advance()':
[Error] expected primary-expression before '<<' token

标签: c++

解决方案


我想你是想写

cout<<day<<"/"<<month<<"/"<<year<<endl;

代替

cout<<date<<"/"<<month<<"/"<<year<<endl;

在 setDate 和 Advance 函数中


推荐阅读