"C++ 벡터 for 루프"의 두 판 사이의 차이

잔글 (Jmnote님이 C++ vector for 루프 문서를 C++ 벡터 for 루프 문서로 이동했습니다)
 
(차이 없음)

2023년 9월 3일 (일) 03:01 기준 최신판

1 개요[ | ]

C++ vector for loop
C++ 벡터 for 루프
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v = {1, 2, 3, 4, 5};
  for(int i=0; i<v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v = {1, 2, 3, 4, 5};
  vector<int>::iterator it;
  for(it=v.begin(); it<v.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
}
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v = {1, 2, 3, 4, 5};
  for(auto& el : v) {
    cout << el << " ";
  }
  cout << endl;
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}