簡體   English   中英

upper_bound和lower_bound在不同的標頭中?

[英]upper_bound and lower_bound in different headers?

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中的所有符號。

基本上,您可以保證所要求的標頭中的符號將可用。 額外可以來。

因此,這是合規的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM