Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:53:53+00:00 2026-05-27T22:53:53+00:00

I have written a code for finding intersection of two multimap which will compare

  • 0

I have written a code for finding intersection of two multimap which will compare
values related to key and fetch us a map containing a comman elements (combination
of key and value) from two map. This is displaying one part of string as pointer
and rest as usual.

#include <string>
#include <iostream>
#include <map>
#include <iterator>
#include <stdio.h>

template <class InputIterator1, class InputIterator2, class OutputIterator>

/* templet function to return common elements od two map  */

OutputIterator map_intersection ( InputIterator1 first1, InputIterator1 last1,
        InputIterator2 first2, InputIterator2 last2,
        OutputIterator result )
{
    while (first1!=last1 && first2!=last2)
    { 
        if (*first1<*first2) ++first1;
        else if (*first2<*first1) ++first2;
        else {  
            const char*abc= new char[15];
            const char*def= new char[15];
            /* Below code inserts the common element in result map */ 
            if(strcmp((first1->second.c_str()),(first2->second.c_str()))==0)
            {                                                                   
                result.insert(std::pair<std::string,std::string>(first1->first,first1->second));
                ++first1;
                ++first2;
            }
            else
            {
                ++first1;
                ++first2;  
            } 
        } 
    }
    return result;

}

using namespace std;

int main()
{
    std::multimap<string, string> m;
    std::multimap<string, string>::iterator it2;
    std::multimap<string, string> intersection;
    std::multimap<string, string> common;
    std::multimap<string, string> it3;

    cout <<"Making Map m "<<endl;
    m.insert(pair< string, string>("1 2"," 22 3" ));
    m.insert(pair< string, string>("1 2"," 21 4" ));
    m.insert(pair< string, string>("2 1"," 31 3" ));

    cout <<"Making Map c "<<endl;
    std::multimap<string, string> c;
    c.insert(pair< string, string>("1 2"," 22 3" ));
    c.insert(pair< string, string>("1 2"," 22 4" ));
    c.insert(pair< string, string>("2 1"," 31 3" ));

    cout << "Elements in common map are: " << endl;
    it3=map_intersection (m.begin(), m.end(), c.begin(), c.end(),common);

    cout << " am i out of the map_intersection loop " << endl;
    cout << " size of common map is : " << it3.size()<< endl;
    for(it2 =it3.begin(); it2!=it3.end();it2++)
    {   
        cout << "first common element is : " <<  
            cout << it2->first << " " << it2->second <<"  " << endl;
    }
    getchar();
}

Expected output :

1 2   22 3
2 1   31 3 

Output on console:

0x4483c41 2   22 3
0x4483c42 1   31 3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:53:53+00:00Added an answer on May 27, 2026 at 10:53 pm

    From your code:

    cout << "first common element is : " <<  
        cout << it2->first << " " << it2->second <<"  " << endl;
        ^^^^
    

    You are outputting cout itself to cout, which causes the hex value to be printed. You need to either remove cout from the second line, or make these two separate statements.

    The reason that the hex value gets printed is that basic_ios has an operator void* which returns a pointer. This pointer is passed to the overload of basic_ostream::operator<< which prints a pointer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have written some code for playing a .wav through my application. Now I
I have written this code to join ArrayList elements: Can it be optimized more?
I have written some code to ensure that items on an order are all
I have written some code to look at properties using reflection. I have retrieved
I have written this code to convert string in such format 0(532) 222 22

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.