相关疑难解决方法(0)

binary_search in c ++意外行为

下面的片段给我回复0.我预计它会是1.这里发生了什么问题?

#include <iostream>
#include <iterator>
#include <ostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  vector<int> v;
  int arr[] = {10,20,30,40,50};
  v.push_back(11);
  v.push_back(22);
  copy(arr,arr + sizeof(arr)/sizeof(arr[0]),back_inserter(v));  // back_inserter makes space starting from the end of vector v
  for(auto i = v.begin(); i != v.end(); ++i){
    cout << *i << endl;
  }
  cout << endl << "Binary Search -  "  << binary_search(v.begin(), v.end(), 10) <<endl; // returns bool 
}
Run Code Online (Sandbox Code Playgroud)

我正在使用gcc /usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper

c++ stl

2
推荐指数
1
解决办法
179
查看次数

标签 统计

c++ ×1

stl ×1