달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

///////////////////////////////////////////////////////////////

// 02. 범위기반 for 문 Example

// C++11은 Java나 C#에서 제공하는 범위기반 for문을 제공한다.

// * for 루프가 간단해 짐

// * 루프의 순회값(i)의 초기값을 정해줄 필요가 없다.

// * 배열의 길이를 지정해주지 않아도 된다.

// * 언제까지 순회(범위)해야 할지 지정할 필요가 없다.

///////////////////////////////////////////////////////////////////

#include <iostream>

#include <vector>

using namespace std;


int main()

{

    vector<int> vInt;

    for(auto i=0; i<10; ++i)

    {

        vInt.push_back(i);

    }


    //C++03 표준

    cout << "C++03 standard"<<endl;

    std::vector<int>::const_iterator it;

    for(it = vInt.begin(); it != vInt.end(); ++it)

    {

        std::cout << *it << std::endl;

    }


    //C++11 표준

    cout<< "C++11 standard"<<endl;

    for(auto i: vInt)  //for ( for-range-declaration : expression )

    {

        std::cout << i <<std::endl;

    }


    getchar();

    return 0;

}



'karma( 업 ) > C_C++' 카테고리의 다른 글

*& reference to pointer  (0) 2018.12.03
09. std::tuple( C++11로 가자 )  (0) 2018.11.01
01. auto( C++11으로 가자 )  (0) 2018.11.01
01. C++11의 특징( C++11으로 가자 )  (0) 2018.11.01
C++11으로...  (0) 2018.11.01
Posted by 생짜
|