通过指针间接地修改结构体结构成员内容
在书上看到一个例子,实验一下调试不通,不清除错到哪里了?刚刚学习C++(没有C基础),请不要见笑。
#include<iostream>
using namespace std;
struct couple
{
char man[];
char woman[];
};
void break_up(struct couple *ptr);
int main()
{
struct couple Camastra={"John","Sara"};
struct couple *ptr;
ptr=&Camastra;
cout<<"Before break_up,Camstra couple was:\n";
cout<<Camastra.man<<""<<Camastra.woman<<"\n";
break_up(ptr);
cout<<"After break_up,Camstra couple is:\n";
cout<<Camastra.man<<""<<Camastra.woman<<"\n";
system("pause");
}
void break_up(struct couple *ptr)
{
ptr->woman='C';
}
char man[];这样的声明也不是很理解。