c++ - Is it bug in std::includes or am I doing something wrong
问题描述
C++ STL includes
(http://www.cplusplus.com/reference/algorithm/includes/) Test whether sorted range includes another sorted range
Returns true if the sorted range [first1,last1) contains all the elements in the sorted range [first2,last2)
void Test_STL_Includes() {
vector<char>secondRowInKeyboard{ 'a','A','s','S','d','D','f','F','g','G','h','H','j','J','k','K','l','L' };
sort(secondRowInKeyboard.begin(), secondRowInKeyboard.end());
string s("Alaska");
sort(s.begin(), s.end());
if (includes(secondRowInKeyboard.begin(), secondRowInKeyboard.end(), s.begin(), s.end()))
{
cout << "Matches";
}
else
{
cout << "Not Matches";
}
}
Expected: "Matches"
Actual: "Not Matches"
Am I making some mistake?
解决方案
It doesn't match because the "needle" contains two a
but the "haystack" only has one a
.
See also: What does std::includes actually do? ; another way to state it is that the set intersection must equal the second set.
推荐阅读
- sql - 创建视图时如何循环
- c++ - 为什么它需要一个右值复制构造函数,即使它不会被调用?
- android - 如何完成一个活动并在另一个活动中指定片段?
- arrays - 使用 react js 合并并显示表中的对象数据数组
- android - 如何在示例应用程序 android 中显示 Boot Flow 消息?
- php - 实时搜索结果显示在新页面上
- azure - 如何从 Web 获取 excel 文件并将其存储在 azure blob 存储中
- git - 带有 git 私有仓库的 Jenkins kubernetes 插件
- c# - 向 csv 阅读器添加错误处理以检测空文件或不正确的数据类型
- reactjs - 使用 cdn 的材料图标而不是显示其文本时,图标未在反应中显示