C++

int max_num = *std::max_element(vec.begin(), vec.end()); int min_num = *std::min_element(vec.begin(), vec.end()); auto max_num_index = (std::find(vec.begin(), vec.end(), max_num) - vec.begin()); auto min_num_index = (std::find(vec.begin(), vec.end(), min_num) - vec.begin());
c++ type string์— ๋Œ€ํ•œ getline ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค. std::string mystr; std::getline(std::cin, mystr); std::cout
ํ—ค๋”์— ์†ํ•œ sort ํ•จ์ˆ˜๋Š” ๋ฐฐ์—ด ํ˜น์€ ๋ฒกํ„ฐ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. syntax๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. // ๋ฐฐ์—ด std::sort(arr, arr + arr_length); // ๋ฒกํ„ฐ std::sort(vec.begin(), vec.end()); ๋ฐฐ์—ด์˜ ๊ฒฝ์šฐ์—๋Š” (๋ฐฐ์—ด, ๋ฐฐ์—ด + ๋ฐฐ์—ด๊ธธ์ด) ์˜ ํ˜•ํƒœ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๊ธธ์ด๊ฐ€ 5์ธ ๋ฐฐ์—ด my_arr์— ๋Œ€ํ•ด์„œ๋Š” std::sort(my_arr, my_arr + 5); ์ž…๋‹ˆ๋‹ค. ๋ฒกํ„ฐ์˜ ๊ฒฝ์šฐ์—๋Š” ํ•ญ์ƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
ยทC++/๊ธฐํƒ€
์ €๋ฒˆ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ฃฌ ๋ณต์‚ฌ ๋ฐฉ์‹์˜ ๋Œ€์ž… ์—ฐ์‚ฐ์ž ์˜ค๋ฒ„๋กœ๋”ฉ์€ l-value์— ๋Œ€ํ•ด์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ฃฐ ์ด๋™ ๋Œ€์ž… ์—ฐ์‚ฐ์ž ์˜ค๋ฒ„๋กœ๋”ฉ์€ r-value๋ฅผ ๋‹ค๋ฃน๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ ์กฐ๊ฐ์„ ์‚ดํŽด๋ด…์‹œ๋‹ค. Mystring s1; s1 = Mystring{"Ricky"};// Move Assignment ์—ฌ๊ธฐ์„œ empty string์„ ๋‹ด๋Š” Mystring ๊ฐ์ฒด s1์„ ์„ ์–ธํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  s1์— Mystring{"Ricky"}๋ฅผ ํ†ตํ•ด์„œ Ricky๋ผ๋Š” ๋ฌธ์ž์—ด์„ ์†์„ฑ์œผ๋กœ ์ง€๋‹Œ Mystring ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ์ ์€, s1์— ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ƒˆ๋กœ์šด ์ด๋ฆ„ ์—†๋Š” ์ž„์‹œ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ , ๊ทธ ๊ฐ’์„ s1์— ์ €์žฅ์„ ํ•œ ๋’ค์— ์ž„์‹œ ๊ฐ์ฒด๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด r-value ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์•„์‹œ๋‹ค์‹œํ”ผ ์ด๋Ÿฐ..
Chan Lee
'C++' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก