自定義數據類型

#include<iostream>
#include<string>
using namespace std;
typedef double weight,tall;
struct student{
    int number; 
    int score;
    string name;
    weight w;
    tall t;
}; 
int main(){
    student s[4]={{1,100,"wendy"},
    {2,98,"susan"},
    {3,87,"joker"},
    {4,99,"du"}
    };
    cout<<"body check list: "<<endl;
    for(int i=0;i<4;i++)
    {cout<<s[i].name<<"\t["<<i+1<<"]號 tall=";
    cin>>s[i].t; 
    cout<<"\t          weight=";
    cin>>s[i].w;
    }
    return 0;
}

貼上正確的輸出:
這裏寫圖片描述
這裏tall和weight都是自己可以輸入的
先貼上正確的;講講我剛剛錯的地方:
struct student{
int number;
int name;
string score;
weight w;
tall t;
};
可以看到和上面的區別,name和score位置顛倒,結果輸出一直是:
這裏寫圖片描述
另外,struct第三行,得是string不能是int,不然直接報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章