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 7935577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:57:54+00:00 2026-06-03T21:57:54+00:00

I have two maps, tk1 and tk2 with the following structure: std::map<std::string, double>tk1; std::map<std::string,

  • 0

I have two maps, tk1 and tk2 with the following structure:

std::map<std::string, double>tk1;
std::map<std::string, double>tk2;

tk1 contains the following data:

    2011-01-03 2200
    2011-01-04 2209
    2011-01-05 2300

and tk2 contains the following data:

2011-01-03 2450
2011-01-04 2465
2011-01-06 2476
2011-01-07 2457

I have created a set that contains the dates as strings as in

std::set<std::string>dateset;
std::set<std::string>new_dateset;

I created it by iterating through the 2 maps and inserting into the set as in

dateset.insert(it->first);

dateset has the following values:

2011-01-03
2011-01-04
2011-01-05
2011-01-06
2011-01-07

I want to populate new_dateset so it only contains the dates that are in both tk1 and tk2, i.e. new_dateset should contain only

2011-01-03
2011-01-04

I wrote the following:

std::set<std::string>::iterator it1=dateset.begin(), end1=dateset.end();
std::map<std::string, double>::iterator it2=tk1.begin(), end2=tk1.end();
std::map<std::string, double>::iterator it3=tk2.begin(), end3=tk2.end();
while (it1 != end1) {
if (it2->first == *it1) 
new_dateset.insert(it2->first);
++it1;
}

but obviously I am not doing it correctly. Can someone suggest the best way to do this.

  • 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-06-03T21:57:55+00:00Added an answer on June 3, 2026 at 9:57 pm

    Iterate over it1, check if first for each element is in tk2 using the find() method, and insert it into the set if it is there. What you are doing in your example is to check elements in dataset, which contain keys that are in tk1 OR tk2.

    for(; it2 != end2; ++it2) {
      if(tk2.find(it2->first) != end3) new_dataset.insert(it2->first);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
This is kind of last resort.. So I have two maps. typedef std::map <string,
I have two Maps that contain the same type of Objects: Map<String, TaskJSO> a
Say I have two maps, each represented as a 2D array. Each map contains
I have two maps of type Map<Long, Integer>, one named oldValues representing the old
I would like to have a mapping which maps two string into one string.
I have two maps on a page, one is a map of the world,
I have two tables in a SQL Server 2008 environment with the following structure
I have two maps whose keys are String s and whose values are Set<MyObject>
I am working in Java, and have declared two maps as follow: private Map<MyCustomClass,

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.