小编use*_*504的帖子

VS 2010编译器错误"c2678没有运算符发现转换const std :: string",但没有任何东西被声明为const

我的源代码非常简单:

#include <set>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>

using namespace std;

void test() {
    set<string> *S = new set<string>;
    S->insert("hi"); 
    S->insert("lo");
    set<string> *T = new set<string>;
    T->insert("lo");
    set<string> *s = new set<string>;
    set<string>::iterator l=s->begin();
    set_difference(S->begin(),S->end(),T->begin(),T->end(),l);
}
Run Code Online (Sandbox Code Playgroud)

那么为什么我会收到编译器错误:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(4671): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::basic_string<_Elem,_Traits,_Ax>'
Run Code Online (Sandbox Code Playgroud)

集合"s"只是一组字符串,没有任何常量.

c++ stl stl-algorithm

3
推荐指数
1
解决办法
398
查看次数

标签 统计

c++ ×1

stl ×1

stl-algorithm ×1