Assign one structure to another structure : structure « Structure « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

struct Box {
  double length;
  double width;
  double height;
};

int main() {
  Box firstBox = { 80.0, 50.0, 40.0 };

  cout << firstBox.length
       << firstBox.width
       << firstBox.height
       << endl;
       
  Box secondBox = firstBox;   

  secondBox.length *= 1.1;
  secondBox.width *= 1.1;
  secondBox.height *= 1.1;

  cout << secondBox.length 
       << secondBox.width
       << secondBox.height
       << endl;
  
  return 0;
}
805040
885544








8.1.structure
8.1.1.Use memcpy to duplicate structures
8.1.2.Use cin to read data for a structure
8.1.3.const structure parameter
8.1.4.Define structure to record time
8.1.5.structure composition
8.1.6.Using pointers to structure objects: delete the point
8.1.7.Assign one structure to another structure
8.1.8.Use the keyword struct to illustrate a primitive form of class