1

我有如下代码:

#include<set>
#include<iterator>

std::set<std::string> s1;
std::set<std::string> s2;   
std::set<std::string> myresult;

void some_func() {
    std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),std::inserter(myresult,myresult.begin()));
}

这给了我编译错误:

/export/SunStudio/SUNWspro/prod/include/CC/Cstd/./algorithm.cc”,第 2161 行:错误:在“std::copy<__rwstd::__rb_tree<std::string, std::string 之间重载歧义, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std: :set<std::string>>>(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::字符串>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std ::less<std::string>、std::allocator<std::string>>::const_iterator、std::insert_iterator<std::set<std::string>>)”和“copy<__rwstd:: __rb_tree<std::字符串, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std ::insert_iterator<std::set<std::string>>>(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std: :less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std ::string>、std::less<std::string>、std::allocator<std::string>>::const_iterator、std::insert_iterator<std::set<std::string>>)”。(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std: :string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>)”。(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std: :string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>)”。
4

1 回答 1

0

你忘了添加

#include<algorithm>

到你的代码。

于 2012-01-10T12:44:41.003 回答