一个嵌套的结构体数组动态开内存的问题
程序代码:
#include<iostream> #include<fstream> using namespace std; int route_sum,station_sum; struct main_place { char num; char mainPlace[5][30]; }; struct station_name { char name[30]; main_place place; }; struct bus_route { int number; station_name * station; }*route; int main() { fstream f_save("route.dat",ios::app); { char s[40]; cout<<"请输入线路数:"; cin>>route_sum; f_save<<route_sum<<endl; route=new bus_route[route_sum]; for (int i=0;i<route_sum;i++) { printf("请输入第 %d 个线路信息\n",i); cout<<"线路号:"; cin>>route[i].number; f_save<<route[i].number<<" "; cout<<"此线路的站点数为:"; cin>>station_sum; station=new station_name [station_sum]; //主要是这里,结构体bus_route的成员station_name类型的*station怎么动态开内存 for (int t=0;t<station_sum;t++) { cout<<"站点名字:"; cin>>route[i].station[t].name; f_save<<route[i].station[t].name<<" "; cout<<"主要场所数目(不超过5个):"; cin>>route[i].station[t].place.num; } } } return 0; } //谢谢过路的大神!