regarding the usage of set_difference with maps

S

sdilip519

i am using maps with a string in the template argument and i want to
find the difference of two maps into another amp for this i can use the
set_difference function but the arguments of the functions are
iterators.
can any one help me in this how to send the arguments in
to the function.

Thanks in advance.

Regards
Dilip
 
I

Ian Collins

i am using maps with a string in the template argument and i want to
find the difference of two maps into another amp for this i can use the
set_difference function but the arguments of the functions are
iterators.
can any one help me in this how to send the arguments in
to the function.
set_difference( first.begin(), first.end(),
second.begin(), second.end(),
result.begin() );
 
S

sdilip519

this is the same i have done but i am getting an std:pair error asking
some operator should be over loaded . for this i am attaching the code
which i have used.....


#include <map>
#include <algorithm>
#include <functional> // For greater<int>( )
#include <iostream>
#include<vector>

using namespace std;

int main( )
{

map<char*,int> mapobj1;
map<char*,int> mapobj2;
map<char*,int> mapobj3;

mapobj1["one"] = 111;
mapobj1["two"] = 112;
mapobj1["three"] = 113;
mapobj1["four"] = 114;

mapobj2["five"] = 111;
mapobj2["two"] = 112;
mapobj2["three"] = 113;
mapobj2["four"] = 124;

set_difference(mapobj1.begin(),mapobj1.end(),mapobj2.begin(),mapobj2.end(),mapobj3.begin());


}


and the error is


error C2582: 'std::pair<char * const,int>' : 'operator =' function is
unavailable
 
P

Pete Becker

Ian said:
set_difference( first.begin(), first.end(),
second.begin(), second.end(),
result.begin() );

set_difference(first.begin(), first.end(),
second.begin(), second.end(),
back_inserter(result), pred);

where pred takes two pair objects and compares them appropriately. Since
result is a map, you can't overwrite its values, so you need back_inserter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top