c++中struct使用注意事项
1.C++的结构体变量在声明的时候可以省略struct,在c中这样是不可以的,例子如下
#include<iostream>
#include<string>
usingnamespacestd;
structtest{
intnum;
stringname;
};
intmain(void)
{
testt;
t.num=1;
t.name="jack";
cout<<t.num<<""<<t.name<<endl;
}
2.c++的结构体声明可以声明在main()函数中,也可以在main()函数之前,在之前的话,整个程序都可以调用,这也是最常用的方式;而在内部的话,只能在函数内使用,也就是说在声明的函数内可以使用,类似于局部变量的概念。如下
intmain(void)
{
structtest{
intnum;
};
testhello;//right
}
voidt()
{
testt;//wrong
}
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志