不同报头中的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中的任何和所有符号。
基本上,你所能保证的就是你请求的头中的符号是可用的。额外的可以来。
所以这是符合的
相关文章:
- 空集"Out of bound iterator"
- 将张量的"lower diagonal"映射到矩阵,作为将矩阵的下三角形部分提取到向量的推广
- 为什么<<低;和 cout<<v.begin;单独给出错误,但 cout <<(lower.begin());没有给出任何错误,并使代码易于编译
- 使用多个文件时"array bound is not an integer constant before ']' token"
- "A reference may be bound only to an object",为什么"const int &ref = 3;"有效?
- 如何修复"reference cannot be bound to dereferenced null pointer"警告
- 当你有一个像 ::lower 这样的参数时,这在C++中是什么意思
- GCC 检测"subindex out of bound"错误
- 如果我没有得到分段错误,如何找到"index out of bound"
- 一个程序将字符串Upper char更改为Lower char得到错误
- std:: lower的行为在不同的语言环境中是如何变化的?
- 在main中声明Array之前,Array bound不是整型常量
- 获取错误"array bound is not an integer constant before ']' token"
- 如何在C或c++中获得与Java中的toLowerCase或Python中的string.lower()相同的结果
- 在运行时创建结构时"array bound is not an integer constant"