"Original" Learn C + + (arrow symbol)---------C + + Primer Plus (6th edition)

Source: Internet
Author: User

Novice C + + when you specify a struct member, you do not know when to use the. operator, and when to use the-I operator.

Conclusion: If the structure identifier is a struct name, use the period operator, or if the identifier is a pointer to a struct, use the arrow operator.

#include <iostream>structinflatable{Charname[ -]; floatvolume; DoublePrice ;};intMain () {using namespacestd; intA; Only to keep the DOS interface inflatable*ps=Newinflatable; cout<<"Enter Name of inflatable item:"; Cin.Get(Ps->name, -    ); cout<<"Enter volume in cubic feet:"; CIN>> (*PS). Volume; cout<<"Enter Price: $"; CIN>>ps->Price ; cout<<"Name:"<< (*PS) .name<<Endl; cout<<"Volume:"<<ps->volume<<"Cubic feet\n"; cout<<"Price : $"<<ps->price<<Endl;    Delete PS; CIN>>A; To keep the DOS interface onlyreturn 0;}

Output Result:

For example, *PS this structure pointer:

ps->name equivalent to (*ps). Name

"Original" Learn C + + (arrow symbol)---------C + + Primer Plus (6th edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.