天天看點

日學c++之結構體舉例

#include<iostream>

#include<string.h>

#include<stdio.h>

using namespace std;

struct PERSON

{

int age;

float weight;

char sex;

char name[25];

};

int main()

{

PERSON one;

PERSON *p;

p = &one;

p->age = 24;

strcpy_s(p->name, "田da玉");

p->sex = 'M';

p->weight = 60.5;

cout <<"年齡:"<< (*p).age << "\n";

cout <<"姓名:"<< (*p).name << "\n";

cout <<"性别:"<<(*p).sex << "\n";

cout <<"體重(kg):"<< (*p).weight << "\n";

cout << endl;

system("pause");

return 0;

}