C++ 如何在类函数实现文件中格式化以下控制台输出?
问题告诉我: “该类应具有成员函数,以便按以下格式打印日期”C++ 如何在类函数实现文件中格式化以下控制台输出?,c++,C++,问题告诉我: “该类应具有成员函数,以便按以下格式打印日期” 2013年3月15日//showShortDate 2013年3月13日//showLongDate 2013年3月15日//showEuroDate 函数实现文件中的以下内容将不会编译并给出“cout:undeclared identifier”错误。我在主程序.cpp文件中有#include // Date.cpp is the Date class function implementation file #inc
- 2013年3月15日//showShortDate
- 2013年3月13日//showLongDate
- 2013年3月15日//showEuroDate
“cout:undeclared identifier”
错误。我在主程序.cpp文件中有#include
// Date.cpp is the Date class function implementation file
#include "Date.h"
Date::Date(int m, int d, int y)
{ month = m;
day = d;
year = y;
}
Date::Date()
{
month = 1;
day = 1;
year = 2001;
}
void Date::showShortDate()
{
cout << month << "/" << day << "/" << year;
}
void Date::showLongDate()
{
cout << month << " " << day << ", " << year;
}
void Date::showEuroDate()
{
cout << day << " " << month << " " << year;
}
//Date.cpp是日期类函数实现文件
#包括“Date.h”
日期:日期(整数m,整数d,整数y)
{月=m;
d=d;
年份=y;
}
日期::日期()
{
月=1;
日=1;
年份=2001年;
}
作废日期::showShortDate()
{
不能将其更改为:
void Date::showShortDate()
{
std::cout << month << "/" << day << "/" << year;
}
void Date::showLongDate()
{
std::cout << month << " " << day << ", " << year;
}
void Date::showEuroDate()
{
std::cout << day << " " << month << " " << year;
}
void Date::showShortDate()
{
std::cout Argh,我已经重复关闭了这个问题,但是链接的东西是错误的。抱歉。现在需要其他人关闭投票,因为它缺乏基础研究。鉴于OP不知道他/她在做什么,需要一些解释。@phresnel我已经更新了答案,并包含了链接,他可以在其中阅读关于什么是namespa的内容行政长官是。