음악, 삶, 개발

Ranged based for 루프와 vector 본문

개발 공부/C++ 약점공략

Ranged based for 루프와 vector

Lee_____ 2020. 10. 19. 21:19
int main () {
    
    std::vector<int> v = { 0, 1, 2, 3, 4, 5 };

    for (const int& i : v) // access by const reference
        std::cout << i << ' ';
    std::cout << '\n';

    for (auto i : v) // access by value, the type of i is int
        std::cout << i << ' ';
    std::cout << '\n';

    return 0;
}