코드 인 스 턴 스 를 통 해 c+vector 상용 방법 을 분석 합 니 다.
https://stackoverflow.com/questions/4461446/stl-way-to-add-a-constant-value-to-a-stdvector
vector<int> x = {0, 30, 80, 100, 120, 150, 190, 220, 250};
//transform ,bind2nd
transform(x.begin(), x.end(), x.begin(), bind2nd(plus<int>(), 1));
// x
copy(x.begin(), x.end(), ostream_iterator<int>(cout, " "));
결과:x={1 31 81 101 121 151 191 221 251}2.c++는 vector 에 어떤 요소 가 존재 하 는 지 판단 합 니 다(c+는 vector 에 요소 가 존재 하 는 지 판단 합 니 다)
https://www.techiedelight.com/check-vector-contains-given-element-cpp/
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> v = { 4, 7, 5, 2, 6, 9 };
int key = 6;
if (std::count(v.begin(), v.end(), key))
std::cout << "Element found";
else
std::cout << "Element not found";
return 0;
}
결과:Element found3.c++vector
https://stackoverflow.com/questions/17694579/use-stdfill-to-populate-vector-with-increasing-numbers
std::vector
// numeric 헤더 파일 에 정 의 된 iota()함수 템 플 릿 은 연속 T 형식 값 으로 시퀀스 를 채 웁 니 다.
std::iota(seq.begin(), seq.end(), 0);
결과:seq={0,1,2,3,4,5,6,7,8,9}
4.c++한 문장 으로 vector 정 보 를 인쇄 합 니 다(c++print out vector by one statement).
https://stackoverflow.com/questions/10750057/how-to-print-out-the-contents-of-a-vector
vector
//istream_iterator 는 입력 흐름 에서 연속 요 소 를 읽 는 데 사 용 됩 니 다.
copy(x.begin(), x.end(), ostream_iterator
결과:1,2,3,4
5.c++는 vector
https://riptutorial.com/cplusplus/example/11151/find-max-and-min-element-and-respective-index-in-a-vector
vector<int> row_y = { 502, 263, 684, 324, 979 };
//
int row_y_max_index = max_element(row_y.begin(), row_y.end()) - row_y.begin();
cout << "row_y_max_index = " << row_y_max_index << endl;
int row_y_max_value = *max_element(row_y.begin(), row_y.end());
cout << "row_y_max_value = " << row_y_max_value << endl;
//
int row_y_min_index = min_element(row_y.begin(), row_y.end()) - row_y.begin();
cout << "row_y_min_index = " << row_y_min_index << endl;
int row_y_min_value = *min_element(row_y.begin(), row_y.end());
cout << "row_y_min_value = " << row_y_min_value << endl;
결과 반환:row_y_max_index = 4
row_y_max_value = 979
row_y_min_index = 1
row_y_min_value = 263
6.c++vector 에 두 개의 vector 추가(c++append a vector to vector)
https://stackoverflow.com/questions/2551775/appending-a-vector-to-a-vector
vector
vector
y.insert(y.end(), x.begin(), x.end());
결과:y={100,0,30,80,100,120,150,190,220,250}
7.c++복사 벡터(c++복사 벡터)
https://www.geeksforgeeks.org/ways-copy-vector-c/
vector
vector
y.assign(x.begin(), x.end());
결과:y={0,30,80,100,120,150,190,220,250}
8.c++vector 주어진 색인 에 따라 요소 삭제(c++vector delete element based on a given index)
https://iq.opengenus.org/ways-to-remove-elements-from-vector-cpp/
두 번 째 색인 값 과 다섯 번 째 색인 값 을 삭제 하려 면 다음 문 구 를 사용 할 수 있 습 니 다.
vector
//remove(x.begin(), x.end(), 80);
x.erase(x.begin() + 2, x.begin() + 5 + 1);
결과:x={0,30,30,220,80}
9.c++벡터 에 지 정 된 모든 요 소 를 삭제 합 니 다(c++벡터 에 지 정 된 모든 요 소 를 삭제 합 니 다)
https://www.techiedelight.com/erase-elements-vector-cpp/
vector
//vector 의 remove 역할 은 value 와 같은 요 소 를 vector 의 끝 에 두 는 것 이지 만 vector 의 size 를 줄 이지 않 습 니 다.
//vector 에서 erase 의 역할 은 특정한 위치 position 나 한 구간(begin,end)의 요 소 를 삭제 하고 size 를 줄 이 는 것 입 니 다.
x.erase(remove(x.begin(), x.end(), 30), x.end());
결과:x={0 150 220 80}
10.c++는 vector 의 특정한 요소 가 나타 나 는 횟수 를 통계 합 니 다(C++count the number of occurrences of an element in vector)
https://www.geeksforgeeks.org/std-count-cpp-stl/
vector
int n = count(x.begin(), x.end(), 3);
결과 n=3
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
HDU 원활 공사 & & 원활 공사 (차 트 법)모 성 은 도시 의 교통 상황 을 조사 하여 기 존의 도시 도로 통계 표를 얻 었 고 표 에는 모든 도로 가 직접 연 결 된 도시 가 열거 되 어 있다.성 정부의 '원활 한 공사' 목 표 는 성 전체의 어느 두 도시...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.