λ°μν
π‘ λ³Έ λ¬Έμλ 'μλ£ν λ°μ΄ν° νμ (Data Type): κ³ μ κΈΈμ΄ μ μ, νλ³ν(Type Casting)'μ λν΄ μ 리ν΄λμ κΈμ λλ€.
~~~μ 리νμμΌλ μ°Έκ³ νμκΈ° λ°λλλ€.
1. μλ£ν (Data Type)
λ°μ΄ν° νμ (Data Type)
κΈ°λ³Έν | void | – | – |
λ¬Έμν | (signed) char | 1 byte | -128 ~ 127 |
unsigned char | 1 byte | 0 ~ 255 | |
wchar_t | 2 byte | 0 ~ 65,535 | |
μ μν | bool | 1 byte | 0 ~ 1 |
(signed) short (int) | 2 byte | -32,768 ~ 32,767 | |
unsigned short (int) | 4 byte | 0 ~ 65,535 | |
(signed) int | 4 byte | -2,147,483,648 ~ 2,147,483,647 | |
unsigned int | 4 byte | 0 ~ 4,294,967,295 | |
(signed) long (int) | 4 byte | -2,147,483,648 ~ 2,147,483,647 | |
unsigned long (int) | 4 byte | 0 ~ 4,294,967,295 | |
__int8 | 1 byte | -128 ~ 127 | |
__int16 | 2 byte | -32,768 ~ 32,767 | |
__int32 | 4 byte | -2,147,483,648 ~ 2,147,483,647 | |
__int64 | 8 byte | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 | |
μ€μν | float | 4 byte | 3.4E-38(-3.4*10^38) ~ 3.4E+38(3.4*10^38) (7digits) |
(long) double | 8 byte | 1.79E-308(-1.79*10^308) ~ 1.79E+308(1.79*10^308) (15digits) |
κ³ μ κΈΈμ΄ μ μ νμ: #include <cstdint>
- int8_t
- int16_t
- int32_t
- int64_t
- uint8_t
- uint16_t
- uint32_t
- uint64_t
μ μ νμ μ¬μ©μ νμ κ³ μ κΈΈμ΄ μ μ νμμ μ¬μ©νκ³ , ν¬κΈ°λ₯Ό λͺ¨λ₯΄λ κ²½μ° 64_tλ₯Ό μ¬μ©νμΈμ.
ꡬ쑰체(struct)μ ν΄λμ€(class)
structμ classλ λ³μκ° κΈ°λ³Έμ μΌλ‘ μΈλΆμμ μ κ·Ό κ°λ₯νμ§ μλμ§λ₯Ό μ μΈνλ©΄ ν° μ°¨μ΄λ μμ΅λλ€.
ꡬκΈμμλ structμ μ©λ‘λ₯Ό classμ ꡬλΆνκΈ° μν΄ structμλ μλ¬΄λ° ν¨μλ λ£μ§ μλλ‘ νκ³ μμ΅λλ€.
κ°κΈμ structλ μλ£λ€μ (ν¨μλ₯Ό μΆκ°νμ§ λ§κ³ ) λ¨μν λ¬Άλ ꡬ쑰체λ‘λ§ μ¬μ©ν΄ μ£ΌμΈμ.
2. νλ³ν (Type Casting)
λ¬Έμ <-> μ«μ
1) std::string -> μ«μ μλ£ν: stoi, stol, stod, stof
std::string str_i = "22";
std::string str_li = "2144967290";
std::string str_f = "3.4";
std::string str_d = "2.11";
int i = stoi(str_i);
long int li = stol(str_li);
float f = stof(str_f);
double d = stod(str_d);
2) char -> μ«μ μλ£ν
int num = atoi("2019")β
3) std::string -> char *
std::string str = "std::string to const char*";
const char *cc = str.c_str(); // const char* cc = &str[0];
char * c = const_cast<char *>(cc);
4) Byte String -> μ«μ μλ£ν
int num = std::stoi(str, nullptr, 16);
μ°Έκ³
- [Blog] μλ£νμ ν¬κΈ° λ° λ²μ: https://myblog.opendocs.co.kr/archives/1230
λ°μν