티스토리 뷰
728x90
<코드>
#include <iostream>
using namespace std;
struct Country {
string name;
string capital;
string continental;
int population;
int area;
} C;
int main() {
// 구조체
Country country001;
country001.name = "Korea";
country001.capital = "Seoul";
country001.continental = "Asia";
country001.population = 100000000;
country001.area = 50000000;
cout << "country001 = " << endl;
cout << country001.name << endl;
cout << country001.capital << endl;
cout << country001.continental << endl;
cout << country001.population << endl;
cout << country001.area << endl << endl;
Country country002 = {
"Russia",
"Moscow",
"Europe",
500,
1000,
};
cout << "country002 = " << endl;
cout << country002.name << endl;
cout << country002.capital << endl;
cout << country002.continental << endl;
cout << country002.population << endl;
cout << country002.area << endl << endl;
cout << "C 001 = " << endl;
cout << C.name << endl;
cout << C.capital << endl;
cout << C.continental << endl;
cout << C.population << endl;
cout << C.area << endl << endl;
C.name = "국가명";
C.capital = "수도";
C.continental = "대륙";
C.population = 100;
C.area = 200;
cout << "C 002 = " << endl;
cout << C.name << endl;
cout << C.capital << endl;
cout << C.continental << endl;
cout << C.population << endl;
cout << C.area << endl << endl;
// 구조체의 배열
Country countryArr[] = {
{"한국", "서울", "아시아", 1111, 2222},
{"러시아", "모스코바", "유럽", 11, 22},
};
cout << "countryArr[0] = " << endl;
cout << countryArr[0].name << endl;
cout << countryArr[0].capital << endl;
cout << countryArr[0].continental << endl;
cout << countryArr[0].population << endl;
cout << countryArr[0].area << endl << endl;
cout << "countryArr[1] = " << endl;
cout << countryArr[1].name << endl;
cout << countryArr[1].capital << endl;
cout << countryArr[1].continental << endl;
cout << countryArr[1].population << endl;
cout << countryArr[1].area << endl << endl;
return 0;
}
<결과>
country001 =
Korea
Seoul
Asia
100000000
50000000
country002 =
Russia
Moscow
Europe
500
1000
C 001 =
0
0
C 002 =
국가명
수도
대륙
100
200
countryArr[0] =
한국
서울
아시아
1111
2222
countryArr[1] =
러시아
모스코바
유럽
11
22
728x90
'C++' 카테고리의 다른 글
[C++] 입력값 받기 (0) | 2023.12.20 |
---|---|
[C++] char[] 배열의 사용 (0) | 2023.12.20 |
[C++] auto 자료형 사용방법 (0) | 2023.12.20 |
[C++] type casting 자료형 변환 (0) | 2023.12.20 |
[C++] 자료형 bool (0) | 2023.12.20 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 안드로이드
- simpleName
- 로그캣
- new project
- create new project
- 화면 고정
- create project
- screenorientation
- 코틀린
- web chrome view
- javaClass
- logcat
- 영문 키보드
- custom web view
- web view
- andorid
- 웹뷰
- defaultInputmode
- logtag
- check permissions
- kotlin
- permissions
- Inputmode
- 클래스 이름
- android studio
- 외부 브라우저
- web view settings
- Android
- 화면 방향 고정
- StringWriter
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함