Structure的結構
struct _point{
int x;
int y;
};
struct point a;
int x;
int y;
};
struct point a;
範例:輸入座標
#include <iostream>
using namespace std;
int main(){
struct _point{
int x;
int y;
};
struct _point a;
cin >> a.x;
cin >> a.y;
cout <<"a的x座標為" << a.x<<endl;
cout <<"a的y座標為" << a.y<<endl;
}
using namespace std;
int main(){
struct _point{
int x;
int y;
};
struct _point a;
cin >> a.x;
cin >> a.y;
cout <<"a的x座標為" << a.x<<endl;
cout <<"a的y座標為" << a.y<<endl;
}
使用typedef
typedef struct _point{
int x;
int y;
}point;
point a; //可像宣告變數一樣宣告point
int x;
int y;
}point;
point a; //可像宣告變數一樣宣告point
typedef範例:輸入座標
#include <iostream>
using namespace std;
int main(){
typedef struct _point{
int x;
int y;
}point;
point a;
cin >> a.x;
cin >> a.y;
cout <<"a的x座標為" << a.x<<endl;
cout <<"a的y座標為" << a.y<<endl;
}
using namespace std;
int main(){
typedef struct _point{
int x;
int y;
}point;
point a;
cin >> a.x;
cin >> a.y;
cout <<"a的x座標為" << a.x<<endl;
cout <<"a的y座標為" << a.y<<endl;
}
參考資料
https://drive.google.com/file/d/0BzXo90HhqACINlpvQmNSVXowdlE/edit