C++/๊ธฐํƒ€

ยทC++/๊ธฐํƒ€
2023.12.23 ๊ธฐ์ค€ M2 MAC ๋””๋ฒ„๊น… ๊ด€๋ จ ํŒŒ์ผ๋“ค ๊ธฐ๋ก codelldb extension ์‚ฌ์šฉ ์ค‘ //c_cpp_properties.json { "configurations": [ { "name": "Mac", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "macFrameworkPath": [ "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" ], "compilerPath": "/usr/bin/clang", "cStandard": "c17", "cppStandard": ..
ยทC++/๊ธฐํƒ€
ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ํ•˜๋‹ค ๋ณด๋ฉด 2๊ฐœ์˜ ๋ณ€์ˆ˜์— ๋Œ€ํ•ด์„œ ์„œ๋กœ์˜ ๊ฐ’์„ ๊ตํ™˜ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. swap ํ•จ์ˆ˜๋ฅผ ์“ฐ๋ฉด ํŽธํ•˜์ง€๋งŒ, ์ง์ ‘ ํšจ๊ณผ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•  ๋•Œ๋„ (ํ˜น์‹œ?) ์žˆ์„ ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ๊ฐ€๋ น a = 40, b = 30์ผ ๋•Œ a = 30, b = 40์œผ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ €๋งŒ ๊ทธ๋Ÿฐ์ง€ ๋ชจ๋ฅด๊ณ˜์ง€๋งŒ, ํ•ญ์ƒ ๋ณด์กฐ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ด์„œ ์ด ๋ฐฉ๋ฒ•์„ ํ•ด๊ฒฐํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. int n ๊ฐ™์€ ๋ณ€์ˆ˜์— a ๋‚˜ b ์ค‘ ํ•˜๋‚˜๋ฅผ ์ €์žฅํ•ด ๋†“๊ณ , ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ์ด์ฃ . int a {40}; int b {30}; int n {}; n = a; a = b; b = n; cout
ยทC++/๊ธฐํƒ€
C++์—์„œ ๋žœ๋คํ•œ ์ˆซ์ž๋ฅผ ์–ป๋Š” ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์šฐ์„ , ์ €ํฌ๊ฐ€ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜๋“ค์ด ํฌํ•จ๋œ ํ—ค๋”๋ฅผ ํฌํ•จ์‹œํ‚ต๋‹ˆ๋‹ค. (์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋Š” https://en.cppreference.com/w/cpp/header/cstdlib ์— ์žˆ์Šต๋‹ˆ๋‹ค.) #include #include // cstdlib ํ—ค๋” ์ถ”๊ฐ€ ๊ทธ๋ฆฌ๊ณ  ์ €ํฌ๊ฐ€ ์›ํ•˜๋Š” ๋žœ๋ค ์ˆซ์ž์˜ ๋ฒ”์œ„๋ฅผ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•œ ๋‘๊ฐ€์ง€ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. ์ €๋Š” ์ฃผ์‚ฌ์œ„์—์„œ ์ฒ˜๋Ÿผ 1๊ณผ 6์„ ๊ณ ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ฃผ์˜ํ•  ์ ์€ 1๊ณผ 6์ด ์ œ์™ธ๋œ 2-5์˜ ๋ฒ”์œ„๊ฐ€ ๋Œ€์ƒ์ด ์•„๋‹ˆ๊ณ , 1๊ณผ 6์„ ํฌํ•จํ•ด์„œ 1~6 ์‚ฌ์ด์—์„œ ์ˆซ์ž๊ฐ€ ๊ฒฐ์ •๋ฉ๋‹ˆ๋‹ค. (์ด๋ฆ„์€ ์›ํ•˜์‹œ๋Š”๋Œ€๋กœ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.) ๋‹ค์Œ์œผ๋กœ๋Š” ๋ช‡๋ฒˆ์˜ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์€์ง€๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์€ ๊ผญ ์„ ์–ธ์œผ๋กœ ํ•˜์ง€ ์•Š๋”๋ผ๋„ for๋ฌธ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์œผ๋‚˜, ์ดํ•ด..
ยทC++/๊ธฐํƒ€
iomanip library๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์‹ค์ˆ˜ํ˜• ์ž๋ฃŒ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ, ์†Œ์ˆ˜์  ๋ช‡๋ฒˆ์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผ์„ ํ•  ์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜•์‹ // FORMAT # include cout
Chan Lee
'C++/๊ธฐํƒ€' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)