手机
当前位置:查字典教程网 >编程开发 >C语言 >c++中struct使用注意事项
c++中struct使用注意事项
摘要:1.C++的结构体变量在声明的时候可以省略struct,在c中这样是不可以的,例子如下#include#includeusingnamesp...

1.C++的结构体变量在声明的时候可以省略struct,在c中这样是不可以的,例子如下

#include<iostream> #include<string> using namespace std; struct test{ int num; string name; }; int main(void) { test t; t.num=1; t.name="jack"; cout<<t.num<<" "<<t.name<<endl; }

2.c++的结构体声明可以声明在main()函数中,也可以在main()函数之前,在之前的话,整个程序都可以调用,这也是最常用的方式;而在内部的话,只能在函数内使用,也就是说在声明的函数内可以使用,类似于局部变量的概念。如下

int main(void) { struct test{ int num; }; test hello;//right } void t() { test t; //wrong }

【c++中struct使用注意事项】相关文章:

C++中strtok()函数的用法介绍

C++函数中return语句的使用方法

c++实现strcat字符串连接库函数的方法详解

c++中的string常用函数用法总结

c语言中static的用法详细示例分析

C++中this指针的用法及介绍

深入c++中临时对象的析构时机的详解

C++中引用的使用总结

c++中string类成员函数c_str()的用法

c语言中使用BF-KMP算法实例

精品推荐
分类导航