我想知道如何输入/初始化一个 start_date
和 end_date
(它来自一个结构 Date
,其整数为 month
day
和 year
来自函数 `initializeDate。一旦我能够初始化,我假设我将能够在打印输出中使用相同的逻辑成员函数。
struct Date
{
int month;
int day;
int year;
};
void initializeDate(Date &d)
{
cout<<"Please enter the month"<<endl;
cin>>start.month;
cout<<"Please enter the day"<<endl;
cin>>start.day;
cout<<"Please enter the year"<<endl;
cin>>start.year;
string dummy;
getline(cin, dummy);
}
编辑:我收到的错误是“开始”未在此范围内声明。
最佳答案
这是非常基础的,请阅读一本关于 C++ 的好书。在下面发帖是因为您付出了努力:)
void Information::initializeDate(Date &d) //comes from the Information class.
{
// Commented as part of question change!
// Date d; // Guessing that the structure is the private member of the class.
cout<<"Please enter the month"<<endl;
cin>>d.month;
cout<<"Please enter the day"<<endl;
cin>>d.day;
cout<<"Please enter the year"<<endl;
cin>>d.year;
string dummy;
getline(cin, dummy);
}
** 刚刚根据您的问题修改了代码
关于c++ - 从类成员函数打印结构输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331103/