#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <iomanip>
using namespace std;
class Date{
private:
unsigned int day;
unsigned int month;
string monthName;
unsigned int year;
public:
Date();
void printNumeric() const;
void printAlpha() const;
};
#endif
我的头文件
#include "Date.h"
#include <string>
using namespace std;
Date::Date(){
month = 1;
monthName = "January";
day = 1;
year = 1970;
}
void Date::printNumeric() const{
cout << month << "/" << day << "/" << year;
}
void Date::printAlpha() const{
cout << Date::monthName << " " << day << ", " << year;
}
和实际代码。根据测试平台,我的 printNumeric 函数工作正常,但我的 printalpha 没有生成字符串月份名称。我是否应该对 monthName 做些什么,以便它会生成月份名称的用户输入?
最佳答案
删除
关于c++ - 在 C++ 中打印带有类的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21485047/