【发布时间】:2014-04-04 19:16:25
【问题描述】:
我的源代码非常简单:
#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);
}
那么为什么会出现编译器错误:
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>'
集合“s”只是一组字符串,没有任何常量。
【问题讨论】:
-
你需要 back_inserter for l
-
不要“新建”STL 数据结构。 C++ 不是 Java。你只需要
set<string> S;就可以开始使用了。
标签: c++ stl stl-algorithm