12.struct

#include <bits/stdc++>
using namespace std;
#define F first
#define S second
/* 
    結構 struct
    struct 名稱{
        變數 ...
    };   ****** 注意 ";" *******
*/
struct sample{
    int a , b;
    string s;
    pair<int,int> pr;
};
int main(){
    sample S; // 宣告 剛剛的struct 名稱為S 
    /*
        S 像是一個型別的集合 
        在這裡的sample有 =>  兩個int , 一個string , 一個 pair
        使用方法 : 「struct名稱」.「裡面的子物件」
        EX S.a , S.b 分別是存取 S 裡面包含的兩個 int
        EX S.s 代表 sample S 裡面得字串 s
        S.s[0] 則代表 sample S 裡面得字串 s的第一個字
    */
    cin >> S.a >> S.b >> S.s;
    cout << S.s << " " << S.a  << " " << S.b << endl;
    return 0;
}

results matching ""

    No results matching ""