lower_bound
doesn't give any error, but upper_bound
does. On searching, it's present in <algorithm>
headers file.
Why the inconsistency? would be interesting to know.
C++ code:
#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;
}
Output:
/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;
EDIT
$ g++ -v
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2)
When you include any std header, any and all symbols from std may be imported.
Basically, all you are guaranteed is that the symbols in the header you ask for will be available. Extra can come to.
So this is conforming.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.