不同报头中的Upper_bound和lower_bound

upper_bound and lower_bound in different headers?

本文关键字:bound lower Upper 报头      更新时间:2023-10-16

lower_bound没有给出任何错误,但upper_bound有。在搜索,它存在于<algorithm>头文件。

为什么不一致?我很想知道。

c++代码:

#include <iostream>                                                
#include <vector>     
using namespace std;                                               
int main() {                                                       
    vector<int> ans={1,5,7,8};                                     
    cout<< upper_bound(ans.begin(), ans.end(), 16) -ans.begin() <<endl;
    cout<< lower_bound(ans.begin(), ans.end(), 16) -ans.begin() <<endl;
    return 0;                                                      
}     
输出:

/tmp/a.cpp: In function ‘int main()’:
/tmp/a.cpp:7:50: error: ‘upper_bound’ was not declared in this scope
     cout<< upper_bound(ans.begin(), ans.end(), 16) <<endl;

编辑

$ g++ -v
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) 

当您包含任何std头文件时,可以导入std中的任何和所有符号。

基本上,你所能保证的就是你请求的头中的符号是可用的。额外的可以来。

所以这是符合的