C语言可以把一个结构体变量直接赋给另一个结构体变量,各成员的值会自己赋过去;
struct Person {char name[20];int age;int high;
};
......
void CTest1View::OnDraw(CDC* pDC)
{CTest1Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCString str1;struct Person p1, p2, p3;strcpy(p1.name, "John");p1.age = 25;p1.high = 172;p2 = p1;str1.Format("%s, %d, %d", p1.name, p1.age, p1.high);pDC->TextOut(30, 30, str1);str1.Format("%s, %d, %d", p2.name, p2.age, p2.high);pDC->TextOut(30, 60, str1);p3 = p2;p3.high = 198;str1.Format("%s, %d, %d", p3.name, p3.age, p3.high);pDC->TextOut(30, 90, str1);
}
p1、p2、p3都是类型为Person的结构体变量,可以把p1赋给p2、p3;