结构体初始化

1 #include <fstream>
2 #include <iostream>
3 #include <string>
4 #include <io.h>  
 1 typedef struct structInfo{
 2     int a;
 3     int b;
 4     int c;
 5     structInfo()
 6     {
 7         a = 10;
 8         b = 20;
 9     }
10 }structInfo;
1 int main()
2 {
3     structInfo ta;
4     cout << "ta.a = " << ta.a <<", ta.b = " << ta.b<<", ta.c = " << ta.c<< endl;
5     return 0;
6 }

可以模仿C++的构造函数对C中的结构体进行初始化。

输出结果

 

posted @ 2018-07-20 10:45  hudalikm  阅读(206)  评论(0编辑  收藏  举报