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

(새 문서: ==개요== ;C++ vector for loop ;C++ 벡터 for 루프 <syntaxhighlight lang='console'> #include <iostream> #include <vector> using namespace std; int main() { vector<int> v = {1,...)
 
잔글 (Jmnote님이 C++ vector for 루프 문서를 C++ 벡터 for 루프 문서로 이동했습니다)
 
(같은 사용자의 중간 판 4개는 보이지 않습니다)
3번째 줄: 3번째 줄:
;C++ 벡터 for 루프
;C++ 벡터 for 루프


<syntaxhighlight lang='console'>
<syntaxhighlight lang='cpp' run>
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
12번째 줄: 12번째 줄:
   for(int i=0; i<v.size(); i++) {
   for(int i=0; i<v.size(); i++) {
     cout << v[i] << " ";
     cout << v[i] << " ";
  }
  cout << endl;
}
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#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;
}
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#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;
   cout << endl;

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 }}