Advertisement
Felanpro

struct

May 10th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct person //The members in the struct.
  7. {
  8.     string name;
  9.     string lastname;
  10.     int age;
  11.     int weight;
  12.     float height;
  13. };
  14.  
  15. person struct1 = //Give value to the members and give object name.
  16.     {
  17.         "Felix",
  18.         "Nilsson",
  19.         14,
  20.         65,
  21.         163.5
  22.  
  23.     };
  24.  
  25. int main()
  26. {
  27.  
  28.     cout << struct1.name << endl;
  29.  
  30. }
  31.  
  32. /*Why not use an array instead? One array can only store one type of datatype but a struct can store all datatypes in one block.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement