开辟空间以存放一个结构体变量
1 #include <iostream> 2 #include <string.h> 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 6 struct Student 7 { 8 string name; 9 int num; 10 char sex; 11 }; 12 13 int main(int argc, char** argv) { 14 Student *p; 15 p=new Student; 16 p->name="Wang Fun"; 17 p->num=10123; 18 p->sex='m'; 19 20 cout <<p->name<<endl<<p->num<<endl<<p->sex<<endl; 21 delete p; 22 return 0; 23 }