插入多音符:在该值的第一次发生之前,而不是在上次发生之后
Inserting in a multiset: before the first occurence of that value instead of after the last occurence
标题所示多空心在所有相同值的范围内插入一个值。
(ex:在MultiSet 1,2,2,3
中插入2使其成为1,2,2,/*new*/ 2,3
(。
如何在所有相同值的范围开始插入新值?
(ex:在MultiSet 1,2,2,3
中插入2应该使1,/*new*/ 2,2,2,3
(
尝试此
std::multiset<int> mset { 2,4,5,5,6,6 };
int val = 5;
auto it = mset.equal_range ( val ).first; //Find the first occurrence of your target value. Function will return an iterator
mset.insert ( it, val ); //insert the value using the iterator
使用函数insert(iterator hint, const value_type& value)
代替insert(const value_type& value)
。根据文档,这将在hint
之前插入。您可以使用 std::multiset::equal_range
将迭代器置于下限。
相关文章:
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 在类定义之后定义一个私有方法
- 在循环C++中指定字符串之后,不会打印该字符串
- C++宏忽略之后的内容
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- strncpy之后的char数组的错误行为
- 计算十进制 c++ 之后的数字
- "x += x--"之后的 x 是什么?
- 类的前向声明之后的类成员函数定义,在类声明之前
- 为什么将双精度转换为 int 似乎在第 16 位数字之后将其四舍五入?
- execlp() 在 fork() 之后无法正常工作
- 我认为我的代码很好,但它在 cin a 之后停止并且没有进一步?
- 如何在MISRA C++之后实施CRTP
- 在 OpenCV 的 namedWindow 之前或之后初始化 Tesseract
- 检测到堆损坏:在正常块 c++ 动态 2D 数组之后
- C++ 如果在 if 为 true 之后运行,为什么还会这样做
- 在 fork() 之后,我在我的程序中不断得到相同的 pid
- 编写一个程序,帮助Tudio将MIDI音符转换为名称和八度音阶
- OpenSSL C API:如何在程序exec()之后恢复TLS连接?
- 插入多音符:在该值的第一次发生之前,而不是在上次发生之后