c++ - inplace_merge : why isn't inplace_merge merging the strings?

标签 c++

为什么 inplace_merge 不合并下面代码中的字符串?

string src = "abc";
string new_str = "def";
src += new_str;
inplace_merge(src.begin(), src.begin()+3, src.end());
cout << src; // abcdef

编辑:我期待“adbecf”

最佳答案

它确实可以正常工作,但是您选择了错误的测试数据。

std::inplace_merge对序列中两个已排序的连续范围进行合并,类似于合并排序

也就是说,如果你传递字符串adebcf(假设参数设置为你的问题),它将被合并到abcdef。 如果你传递一个字符串abcdef,结果和输入的是一样的,因为这个字符串已经是有序的。

关于c++ - inplace_merge : why isn't inplace_merge merging the strings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11129077/

相关文章:

C++ 系统不使用 "source files"

c++ - Mac OS X/Linux 上的 _vscwprintf

C++:单例类模板导致链接错误?

php - 如何将定义封装到一个类中? (使用 const 然后确定范围)

c++ - 性能:我应该在经常调用的函数中使用全局变量吗?

c++ - 奇怪的段错误

c++ - 如何在 WinApi 中从 HANDLE 制作 FILE*?

c++ - 如何在 C++ 中正确设置 CURRENCY 值

c++ - 将文件的列读入数组

c++ - 使用 typealias 代替定义中类中定义的 typedef