#include 는 C++ 표준 라이브러리에서 유틸리티 함수와 클래스를 제공하는 헤더 파일입니다. 주로 페어(pair), 이동 시멘틱(move semantics), 그리고 다양한 도구를 제공합니다.1. 주요 기능A. std::pair두 개의 값을 함께 저장하는 템플릿 클래스.서로 다른 타입의 데이터를 하나로 묶는 데 유용합니다.사용 예: #include #include int main() { std::pair p = {1, "Hello"}; std::cout B. std::make_pairstd::pair를 생성하는 헬퍼 함수.타입을 명시하지 않아도 자동으로 유추됩니다.#include #include int main() { auto p = std::make_pair(42, "World")..
#include #include int main() { std::string str1 = "Hello, world!"; // 리터럴로 초기화 std::string str2("C++ string"); // 생성자 사용 std::string str3(str1); // 복사 생성자 std::string str4(5, '*'); // 반복 문자 ('*****') std::cout B. 문자열 연산std::string은 다양한 연산을 지원합니다.문자열 연결#include #include int main() { std::string str1 = "Hello, "; std::string str2 = "world!"; std::..
주요 클래스와 함수1. std::exception모든 표준 예외 클래스의 기본 클래스입니다. 예외 객체를 던질 때 catch 블록에서 예외를 포괄적으로 처리할 수 있도록 설계되었습니다. what() 메서드를 통해 예외와 관련된 설명을 반환합니다.#include #include int main() { try { throw std::exception(); // std::exception 예외 던짐 } catch (const std::exception& e) { std::cout 2. std::bad_alloc동적 메모리 할당 실패 시 발생하는 예외 클래스.예: new 연산자가 메모리 할당에 실패하면 이 예외가 발생#include #include int main() { ..
array를 쓰게 해주는 STL같다.#include #include int main() { std::array arr = {1, 2, 3, 4, 5}; std::array zeroArr{}; std::cout 결과값은 2, 0이 나온다. 위는 명시적으로 초기화를, 아래는 그냥 0으로 초기화했다. #include #include int main() { std::array arr = {1, 2, 3, 4, 5}; std::cout Size: 5가 출력된다. sizeof()을 굳이 안해도 잘 출력되는 모습을 볼 수 있다. #include #include int main() { std::array arr = {1, 2, 3, 4, 5}; std::cout operato..
#include namespace FirstGrade { void introduce() { std::cout > x; if(x == 1){ FirstGrade::introduce(); }else{ SecondGrade::introduce(); } return 0;} 그냥 아예 박스라고 생각하면 편할 것 같다. 한마디로 파란공룡 노란공룡이 있는데, 파란 공룡은 상자1에, 노란 공룡은 상자2에 넣어둔다고 치자. 그냥 상자1::공룡()을 입력하면 파란 공룡이 나오고, 상자2::공룡()을 입력하면 노란 공룡이 나오는 식.