->的用法

->运算符叫做“指向结构体成员运算符”,是C语言和C++语言的一个运算符。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using  namespace  std;
class  C
{
public :
     int  num;
     string name;
};
int  main( void )
{
     C obj;
     C *p = &obj;
     p->num = 5;
     p->name =  "Tony" ;
     cout << p->num << p->name << endl;
     return  0;
}

猜你喜欢

转载自www.cnblogs.com/lanclot-/p/11110318.html