088. 구조체 사용하기 ( struct )

jychan99·2021년 12월 11일
0
#include <iostream>
#include <string>
using namespace std;

//구조체는 여러 데이터 타입들을 한데 묶어 사용할수 있는 데이터 묶음입니다.
//C++에는 클래스의 개념이 있기 때문에 구조체를 사용하지 말라는 주장도있지만,
//어쨋든 구조체는 유용하게 사용할 수 있는 데이터 묶음입니다.
struct Princess
{
    string name;
    string father;
    string birthday = "알 수 없음";
}Goryeo[2];
int main()
{
    Princess jungmyung;
    jungmyung.name = "정명공주"; // 구조체명.구조체멤버 로 구조체내부데이터에 접근할 수 있습니다.
    jungmyung.father = "조선 선조";
    jungmyung.birthday = "1603년 6월 27일";

    Goryeo[0].name = "선정왕후";
    Goryeo[0].father = "고려 성종";
    Goryeo[1].name = "효정공주";
    Goryeo[1].father = "고려 현종";

    cout<<" == 조선 공주  == "<<endl;
    cout << jungmyung.name << endl;
    cout << jungmyung.father << endl;
    cout << jungmyung.birthday << endl;

    cout << " == 고려 공주  == " << endl;
    cout << Goryeo[0].name << endl;
    cout << Goryeo[0].father << endl;
    cout << Goryeo[0].birthday << endl << endl;
    cout << Goryeo[1].name << endl;
    cout << Goryeo[1].father << endl;
    cout << Goryeo[1].birthday << endl;

    return 0;
}
profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐍

0개의 댓글

Powered by GraphCDN, the GraphQL CDN