Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 集合中的下界(C+;+;)_C++_Stl - Fatal编程技术网

C++ 集合中的下界(C+;+;)

C++ 集合中的下界(C+;+;),c++,stl,C++,Stl,我有一个集合,我想找到其中不大于x的最大数。(比如下限(x))我应该怎么做?是否有任何预定义的函数 set<int> myset; myset.insert(blahblahblah); int y; //I want y to be greatest number in myset not greater than x 设置myset; myset.insert(blahblahblah); int-y; //我希望y是myset中的最大数,不大于x 您可以这样使用:上界(x)-

我有一个集合,我想找到其中不大于x的最大数。(比如下限(x))我应该怎么做?是否有任何预定义的函数

set<int> myset;
myset.insert(blahblahblah);
int y;
//I want y to be greatest number in myset not greater than x
设置myset;
myset.insert(blahblahblah);
int-y;
//我希望y是myset中的最大数,不大于x

您可以这样使用:
上界(x)--
。上界为您提供了大于x的第一个元素,因此您要查找的元素是该元素之前的元素。如果
上限
返回
begin()

除了下限,还有上限,则需要一个特殊情况


该函数将迭代器返回到严格大于您的值的第一个值。如果返回begin(),则所有值都是,否则从生成的迭代器中减去一个值即可得到您要查找的值。

u不想使用std::set吗?