Speed up development with full-stack environments for every branch.

Learn More

How to use the 'struct' for packing man name and age in C++

271 Runs 1958 Views 452 Copies
Saved

Saved

tianxiasoft 13

tianxiasoft
published 4 years ago

    /* This is C++ sample code for Structure */
    #include <iostream>
    using namespace std;
    
    // declare struct type for person
    struct Person
    {
      string name;	// person's name
    	int age;		// person's age
    	// view person's profile
    	void Profile() 
    	{
    		cout << "My name is " << name.c_str();
    		cout << "\n";
    		cout << "My age is " << age;
    	}
    };
    
    int main()
    {
    	// declare one person
    	Person me;
    
    	// put values to person's property
    	me.name = "jackson";
    	me.age = 30;
    	
    	// print person's profile
    	me.Profile();
    
    	// wait for any key pressing
    	cin.get();
      return 0;
    }
    
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).