C++/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%2Fdn%2Fb2HFvP%2FbtrftmOoPyZ%2FZgcUT1xsSATyn4ekQNSpvK%2Fimg.png)
[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
#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