C++
c++ vector /pair / sort ์ฌ์ฉ ์์
#include #include #include using namespace std; int main() { vector v; v.push_back(pair(1,"ํ๋ก๊ทธ๋๋จธ์ค")); v.push_back(pair(3, "๋ฐฑ์ค")); v.push_back(pair(2, "๊ฟ์ผ")); sort(v.begin(), v.end()); for (int i = 0; i
[c++] std::array / try catch / auto element ์ฐ์ต ์์
์์ #include #include using namespace std; void print(arrayarr) { for (auto ele : arr) cout
[c++] ์ฝ๋ฉํ ์คํธ์์ ios::sync_with_stdio; cin.tie(0); ๋ฅผ ์ฐ๋ฉด ์ข์ ์ด์
์ ์ถ๋ ฅ์์ printf ๋ฐ scanf๋ฅผ ์ฐ์ง ์๊ณ cout ๋ฐ cin์ผ๋ก๋ง ์ ์ถ๋ ฅ์ ํ ์๊ฐ์ด๋ผ๋ฉด, ios::sync_with_stdio(0); cin.tie(0); ๋ฅผ ์จ์ฃผ๋ฉด ์ข๋ค. ์ ์ถ๋ ฅ ์์ด ๋ง์์ง๋๋ผ๋ ์๊ฐ์ ๋จ์ถ์์ผ์ฃผ๋ ํจ๊ณผ๊ฐ ์๊ธฐ ๋๋ฌธ์ด๋ค. ์ฌ์ฉ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ์ด cin๊ณผ cout ํ๊ธฐ ์ ์ main ํจ์์์ ์์ฑํ๋ ๊ฒ์ด๋ค. int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; getline(cin,s); cout ์ ๋ ฅ์ ํ ๋์ ๋ง์ง๋ง ์ ๋ ฅ์ ํ๊ธฐ ์ ์ ์ถ๋ ฅ ๋ฒํผ๋ฅผ ๋น์์ฃผ๊ฒ ๋๋ค. stream์ tieํ๋ฉด ๋ค๋ฅธ stream์์ ์ ์ถ๋ ฅ์์ฒญ์ด ์ค๊ธฐ์ ์ stream์ flush๋๋ค๋ ๊ฒ์ ์ดํดํ๋ค๋ฉด cin.tie(0);..
![[c++] ๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด์ ์
๋ ฅํ๊ธฐ ์ข์ ํจ์ getline()](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fb2HFvP%2FbtrftmOoPyZ%2FAAAAAAAAAAAAAAAAAAAAAJzycLBpKX54I4c5wClQ11YBjO72IEYe-huYS93DtorI%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1759244399%26allow_ip%3D%26allow_referer%3D%26signature%3DMdSOshZZqwXJZ2Gx%252FGqMfKQSgUM%253D)
[c++] ๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด์ ์ ๋ ฅํ๊ธฐ ์ข์ ํจ์ getline()
์ผ๋ฐ string ๋ณ์์ ๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด์ ์ ๋ ฅํ๋ฉด ์ค๋ฅ๊ฐ ๋๋ค. ๊ฐ๋ น ์๋์ ๊ฐ์ main ํจ์์์ k์ [๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด] ์ด๋ผ๊ณ ์ ๋ ฅํ๋ฉด ์ค๋ฅ๊ฐ ๋๋ค. int main() { string k; cin >> k; cout
c++ ํน์ ํจ์์ ์ธ์๋ก ๋ฐฐ์ด์ฃผ์๋ฅผ ๋๊ธฐ๋ฉด?
์ฃผ์๋ฅผ ๋๊ฒผ๊ธฐ ๋๋ฌธ์ funcํจ์๊ฐ ๋๋๊ณ ๋ฉ์ธํจ์๋ก ๋์๊ฐ๋ funcํจ์์์ ์ด๊ธฐํํ ๊ฐ์ผ๋ก ์ถ๋ ฅ๋๋ค. #include using namespace std; void func(int arr[]) { arr[0] = 10; } int main() { int arr[3] = { 1,2,3 }; func(arr); cout
[Win api] CreateWindow
๋ณธ๋ฌธ์์๋ ์๋ ํ์ด๋ผ์ดํธ ๋ถ๋ถ์ ์ธ๋ถ์ ์ผ๋ก ๋ค๋ฃฐ ๊ฒ์ด๋ค. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (!hWnd) //์๋์ฐ์ฐฝ์ ์์ฑ ๋ชปํ์ ๊ฒฝ์ฐ๋ฅผ ์ํ ์์ธ์ฒ๋ฆฌ๋ฌธ์ด๋ค. { return FALSE; } CreateWindow๋ฅผ ํ๋ฉด ๋ฌด์กฐ๊ฑด ์๋์ฐ ํธ๋ค์ด ๋ง๋ค์ด์ง๋ค. ์ค์ ์๋์ฐ์ฐฝ์ ๋ง๋ค์ด๋ธ๋ค. ์์ฑํ ์๋์ฐ์ ํธ๋ค์ ๋ฐํํด์ค ์ค์ ์ฝ๋ ; HWND hW..
[Win api] InvalidateRect vs updatewindow
1. InvalidateRect ํ๋ฉด์ ๋ฌดํจํํด์ฃผ์ด WM_PAINT ์ ํธ๋ฅผ ๋ณด๋ด๋๋ก ํ๋ค. ์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ invalidateRect๋ WM_PAINT๋ฅผ ์ง์ ํธ์ถํ์ง ์๋๋ค. InvalidateRect ํจ์๋ ๋ฌดํจํ ์์ญ๋ง์ ์ง์ ํด ๋๊ณ ์ด ์์ญ์ ์ฒ๋ฆฌํด ๋ฌ๋ผ๋ ์ ํธ๋ง์ ์ค์ ํ๊ฒ ๋๋ค. ์ด๊ฒ์ WM_PAINT ๋ฉ์ธ์ง์ Flag๋ฅผ ์ค์ ํ๋ ๊ฒ์ด๋ค. ์์คํ ์ด ๋ฉ์์ง ํ์ ์๋ ๋ค๋ฅธ ๋ฉ์ธ์ง๋ฅผ ์ฒ๋ฆฌํด๋์ ๋ค ๋ฌดํจํ ์์ญ์ ์บ์นํ๋ฉด WM_PAINT๋ฅผ ํธ์ถํ๋ค. (๊ฐฑ์ ์์ ์ง์ฐ ์์) 2. updatewindow ๋ฉ์์ง ํ๋ฅผ ๊ฑฐ์น์ง ์๊ณ WM_PAINT๋ฅผ ์ง์ ํธ์ถํ๋ค. (๊ฐฑ์ ์์ ์ง์ฐ ์์)
[Win api] DC์ WM_PAINT, ๊ทธ๋ฆฌ๊ณ BeginPaint() vs GetDC() ๊ดํ ๋น๊ต
1. DC๋, Device Context - ๊ทธ๋ํฝ ์ถ๋ ฅ์ ํ์ํ ๋ชจ๋ ์ต์ ์ ๋ชจ์๋์ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ฒด๋ก, ์๋์ฐ์ฆ์์๋ ์ถ๋ ฅ์ฅ์น์ ๋ฌด์์ธ๊ฐ๋ฅผ ์ถ๋ ฅํ๊ธฐ ์ํด์๋ ๋ฐ๋์ DC๊ฐ ํ์ํ๋ค. ๋ณดํต DCํธ๋ค์ ์ป์ ํ ์ถ๋ ฅํ๋ค.(DCํธ๋ค์ ์ถ๋ ฅ๋์์ ๋ํ๋ด๋ ๊ตฌ๋ถ ๋ฒํธ๋ผ๊ณ ์๊ฐํ๋ฉด ์ฝ๋ค.) ๋ชจ๋ ๊ทธ๋ํฝ ํจ์๋ค์ ์ฒซ๋ฒ์งธ ์ธ์๋ก DCํธ๋ค์ ํ์๋ก ํ๋ค. - GDI์ ์ํด ๊ด๋ฆฌ๋๋ค. (GDI๋ ๊ทธ๋ํฝ ํจ์๋ค์ ๊ตฌํํ๋ ์ผ์ ๋ด๋นํ๋ ์๋์ฐ์ฆ์ ๊ตฌ์ฑ์์์ด๋ค. ๊ทธ๋ํฝ ์ถ๋ ฅ์ ์ํ์ฌ ์์ฉํ๋ก๊ทธ๋จ์ด ์ฌ์ฉํ ์ ์๋ ํจ์์ ๊ทธ์ ๊ด๋ จ๋ ๊ตฌ์กฐ๋ฅผ ์ ๊ณตํ๋ค.) - ์ฆ, ํฐํธ/์์/๊ตต๊ธฐ/์ถ๋ ฅ๋ฐฉ๋ฒ๋ฑ์ด ๋ชจ๋ ์ถ๋ ฅ์ ํ์ํ ์ ๋ณด์ด๋ฏ๋ก ๊ทธ๋ฌํ ์ ๋ณด๋ค์ด DC์ ๋ค ๋ด๊ฒจ ์๋ค๊ณ ๋ณผ ์ ์๋ค. ๊ด๋ จ ์ฝ๋: hdc = GetDC(hWnd); //!..
#include <conio.h> _getch() ์ค๋ช ๊ณผ ์ฝ๋ ์์
#include ์ฝ์ input output ํค๋ํ์ผ์ด๋ค. ์ฝ์์ฐฝ์์ ์ ์ถ๋ ฅํ๋ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํด์ฃผ๋ ํค๋ํ์ผ์ด๋ค. _getch() _getch() ํจ์๋ ๋ฌธ์ 1๊ฐ๋ฅผ ์ ๋ ฅ๋ฐ๋ ํจ์์ด๋ค. Enter๋ฅผ ์น์ง ์๋๋ผ๋ ๋ฌธ์๋ฅผ ๋๋ฅด๋ ์๊ฐ ๋ฐ๋ก ๊ทธ ๋ฌธ์๋ฅผ ๋ฐํํ๊ณ ์ข ๋ฃ๋๋ค. ๋ค์ ๋งํด, cin ์ฒ๋ผ ์ ๋ ฅํ ๋ค์ ๊ตณ์ด ์ํฐ๋ฅผ ์ถ๊ฐํ ํ์์์ด ์ ๋ ฅ ํ์ธํด์ค๋ค. ํค๋ณด๋์์ q๋ฅผ ๋๋ ์ ๋ ๊ฒ์ ์ข ๋ฃํ๊ณ ์ถ์ ๋ ์์ฑํ๋ ์ฝ๋ #include #include #include using namespace std; int main(){ while(true){ char key = _getch(); if(key=='q'|| key=='Q') break; } cout
[C++] ๋ก๋ ์ฝ๋ฉ LOTTO
#include #include using namespace std; int main() { srand((unsigned int)time(0)); int Lotto[45] = {}; for (int i = 0; i