Brise

[C++ 기본 2] 6. STL 본문

프로그램/C,C++

[C++ 기본 2] 6. STL

naudhizb 2022. 3. 2. 23:26
반응형
// 6_STL
#include <iostream>
#include <stack>
#include <vector>
#include <string>  

int main()
{
//    char s1[10] = "hello";
//    char s2[10] = "hello";
//    if (s1 == s2) {}

    // C++ string 클래스 - 문자열을 다루는 타입
    std::string s1 = "hello";
    std::string s2 = "hello";
    if (s1 == s2) {} // ok

    // 동적 배열
    std::vector<int> v(10, 0); // 10개를 0으로 초기화
    v[0] = 3;        // 사용법은 배열과 동일
    v.resize(15);    // 크기 변경도 가능

    for (auto& n : v)
        std::cout << n << std::endl;
}

STL은 template을 기반으로 하여 일반적인 자료구조를 다룰 수 있도록 만든 라이브러리이다. stack, vector, list 등의 자료구조 형태로 STL을 지원한다.

반응형
Comments