c++ - 我想更正我的程序并使其按预期显示初始时间
问题描述
我正在尝试编写一个将时间设置为 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
解决方案
我想你是想写
cout<<day<<"/"<<month<<"/"<<year<<endl;
代替
cout<<date<<"/"<<month<<"/"<<year<<endl;
在 setDate 和 Advance 函数中
推荐阅读
- mongodb - 如果不在数据库中,如何插入许多
- dataframe - 合并 pyspark 数据框中的列
- javascript - 如何更改模板中的日期类型?角 2+
- html - 有没有一种简单的方法可以让第三方向我的网站添加内容?
- ios - 创建一种更简洁的方法来设置具有多个 init 的结构?
- docker - 为 Kafka Insite Docker 运行多个终端
- regex - 在 htaccess 中重写规则写入
- ios - 根据设备Swift的方向更改对象的字体、样式等
- java - 在原生 spring @Query 中使用应用程序属性
- python - 从字典生成熊猫数据框,其值是不同数量的字典列表