首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

STL中 lower_bound与 greater一起使用的一个有关问题

2012-02-15 
STL中 lower_bound与 greater一起使用的一个问题有下面一段代码:#include vector#include algorithm#i

STL中 lower_bound与 greater一起使用的一个问题
有下面一段代码:
#include <vector>
#include <algorithm>
#include <functional> // For greater<int>( )
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
  using namespace std;

  const int VECTOR_SIZE = 8 ;
  typedef vector<int > IntVector ;
  typedef IntVector::iterator IntVectorIt ;

  IntVector Numbers(VECTOR_SIZE) ;
  IntVectorIt start, end, it, location ;

  Numbers[0] = 4 ;
  Numbers[1] = 10;
  Numbers[2] = 10 ;
  Numbers[3] = 30 ;
  Numbers[4] = 69 ;
  Numbers[5] = 70 ;
  Numbers[6] = 96 ;
  Numbers[7] = 100;

  start = Numbers.begin() ; 
  end = Numbers.end() ;  
   
  location = lower_bound(start, end, 10,greater <int>()) ;

  cout << *location<< endl ;
}

为什么输出的是 -33686019?
实验过location-start等于8?不明白为什么?向各位大虾请教.

[解决办法]
应该用
less<int>
[解决办法]
lower_bound(...., op)
op是容器中数据的排序标准,所以容器中的排序顺序应该保证与op一致。

greater<int>()改成less<int>或者不要。

热点排行