gpt4 book ai didi

c++ - 为什么我不能用 std::remove_if 从 std::set 中删除一个字符串?

转载 作者:可可西里 更新时间:2023-11-01 14:53:41 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
remove_if equivalent for std::map

我有一组字符串:

set <wstring> strings;
// ...

我希望根据谓词删除字符串,例如:

std::remove_if ( strings.begin(), strings.end(), []( const wstring &s ) -> bool { return s == L"matching"; });

当我尝试这样做时,出现以下编译器错误:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm(1840): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::basic_string<_Elem,_Traits,_Ax>' 

错误似乎表明 std::string 没有按值复制构造函数(这是非法的)。将 std::remove_ifstd::set 一起使用是否有点不好?我是否应该做其他事情,例如 set::find() 的几次迭代,然后是 set::erase()

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com