Lec20 Struct
Lec20 Struct
Structured Data
11-8
Copyright © 2012 Pearson Education, Inc.
Copyright © 2012 Pearson Education, Inc.
Copyright © 2012 Pearson Education, Inc.
Copyright © 2012 Pearson Education, Inc.
Displaying a struct Variable
• To display the contents of a struct
variable, must display each field
separately, using the dot operator:
cout << bill; // won’t work
cout << bill.studentID << endl;
cout << bill.name << endl;
cout << bill.yearInSchool;
cout << " " << bill.gpa;
11-35
Copyright © 2012 Pearson Education, Inc.
Accessing Structure Members
via Pointer Variables
• Must use () to dereference pointer
variable, not field within structure:
cout << (*stuPtr).studentID;
11-36
Copyright © 2012 Pearson Education, Inc.
From Program 11-8