结构体定义及使用例子!
#include <iostream>
#include <string>
using namespace std;
struct MyStruct
{
int year;
int month;
int day;
};
struct Employee
{
int id;
string name;
MyStruct birthday;
};
void main()
{
cout << sizeof(MyStruct) << endl;
MyStruct *mystruct = new MyStruct;
mystruct->year = 2015;
mystruct->month = 1;
mystruct->day = 30;
cout << "year:" << mystruct->year << ",month:" << mystruct->month << ",day:" << mystruct->day << endl;
MyStruct p = { 2014, 1, 29 };
cout << "year:" << p.year << ",month:" << p.month << ",day:" << p.day << endl;
MyStruct q;
q.year = 2015;
q.month = 1;
q.day = 31;
cout << "year:" << q.year << ",month:" << q.month << ",day:" << q.day << endl;
Employee employee;
employee.id = 100;
employee.name = "justin";
employee.birthday = { 1998, 1, 1 };
cout << employee.name << endl;
cout << "employee id:" << employee.id <<",employee name:"<< employee.name<<",employee birthday:"
<< employee.birthday.year << "-" << employee.birthday.month << "-" << employee.birthday.day << endl;
}