How to use set_intersection with std :: set in VC ++?

I am trying to compile a VC6 project with VC10 ... I get error C2678 with set_intersection: I wrote some examples for understanding. Can someone explain how to compile these fragments?

#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <string>

int main( )
{
    using namespace std;

    typedef set<string> MyType;

    MyType in1, in2, out;
    MyType::iterator out_iter(out.begin()); 

    set_intersection(in1.begin(),in1.end(), in2.begin(), in2.end(), out_iter);
}

Output:

c: \ program files \ microsoft visual \ studio 10.0 \ vc \ include \ algorithm (4494): error C2678: '=' binary: an operator that accepts a left operand of type 'const std :: basic_string <_Elem, _Traits, _Ax > '(or not acceptable conversion)

If I use std::vectorinstead std::set, the compilation was successful. acceptable)

+5
source share
1 answer

Try set_intersection(in1.begin(),in1.end(), in2.begin(), in2.end(), inserter(out, out.begin()) );

, set_intersection , . ( , )

: ​​. . Back_inserter ..

2: ​​ . STL inserter , . chepseskaf.

+6

All Articles