// lower_bound/upper_bound example
#include <iostream> // std::cout
#include <algorithm> // std::lower_bound, std::upper_bound, std::sort
#include <vector> // std::vector
int main() {
int myints[] = {10,20,30,30,20,10,10,20};
std::vector<int> v(myints,myints+8); // 10 20 30 30 20 10 10 20
std::sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30
std::vector<int>::iterator low,up;
low=std::lower_bound (v.begin(), v.end(), 20); // ^
up= std::upper_bound (v.begin(), v.end(), 20); // ^
std::cout << "lower_bound at position " << (low- v.begin()) << '\n';
std::cout << "upper_bound at position " << (up - v.begin()) << '\n';
return 0;
}
이 코드에서는 누군가가 왜 우리가 (낮은 - v.begin()) 및 (- v.begin())을 3 번째와 4 번째 줄에해야하는지 설명 할 수 있습니까? 바닥.std :: lower_bound 사용
내가 할 경우
cout << low << endl;
나는 내가 해달라고 때라도 오류가 두 뺄셈은 벡터의 위치 low
및 up
에서 발견 된 요소의 오프셋을 계산할
cannot bind ‘std::ostream {aka std::basic_ostream}’ lvalue to ‘std::basic_ostream&&’
감사합니다. 정확히 내가 이해할 필요가 있었던 것. 사소한 질문에 죄송합니다. –
반갑습니다. – ssavi