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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:53:59+00:00 2026-05-22T21:53:59+00:00

Supose i have (A,B) (A,C) (A,D) (B,C) (B,D) (C,D) (D,E) in a text file.

  • 0

Supose i have

(A,B)
(A,C)
(A,D)
(B,C)
(B,D)
(C,D)
(D,E)

in a text file. I’ll extract it using regular expressions.

I would like to insert the data in to a container so that it looks like this.

A->B,C,D
B->C,D
C->D
D->E

Which container do I use?

I need to be able to look up data on both the left hand and right hand side of the container, i.e. by key an value. So I need to be able to search/lookup

A,B,C,D in

A->B,C
B->C,D
C->D
D->E

and the B,C in

A->B,C
  • 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-22T21:54:00+00:00Added an answer on May 22, 2026 at 9:54 pm

    std::multimap comes to mind… Is basically a map, but allows duplicates in the map key (i.e. you can have multiple “A” keys, each mapping to a “B”, “C” or “D” key, to continue your example).

    EDIT: In response to Chris’ comment: you insert items into a multimap in the same manner as a map – you make a std::pair object containing the key and value, then insert that into the multimap:

    std::multimap<char, char> myMap;
    myMap.insert(std::pair<char, char>('A', 'B'));
    myMap.insert(std::pair<char, char>('A', 'C'));
    myMap.insert(std::pair<char, char>('A', 'D'));
    myMap.insert(std::pair<char, char>('B', 'C'));
    // ... etc
    

    Assuming here that you literally are examining characters, and A, B, C etc aren’t stand-ins for something else. If they are stand-ins, adjust as appropriate.

    You can then query the multimap for all values under the key ‘A’ as follows:

    typedef std::multimap<char, char>::iterator mmIter; // For brevity...
    std::pair<mmIter, mmIter> iters = myMap.equal_range('A');
    // Iterate over values for key
    for (mmIter iter = iters.first ; iter != iters.second; ++iter)
    {
        // Print out value.
        cout << " " << (*iter).second;
    }
    

    multimap.equal_range returns a pair containing iterators to the first entry matching the key, and the entry immediately following the last entry matching the key. Therefore, these can be used to iterate over the entries, as demonstrated.

    EDIT 2 just realised what you really meant by your comment. Multimap does not natively support bidirectional operation (i.e. lookup on value as well as on key), so you might then need to maintain two multimaps – one for each direction. This can be a pain to do though – it can be tricky ensuring that the two remain properly synchronised.

    Alternatively, I’m sure there’s some Boost class that would serve the purpose (I don’t actually know – I don’t use Boost myself, but I’m sure someone else should be able to provide more detail).

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

Sidebar

Related Questions

Suppose I have a text file that looks like this: 33 3 46 12
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
Suppose I have a text file with data separated by whitespace into columns. I
Suppose I have 500 rows of data, each with a paragraph of text (like
Suppose I have a text file with some data I want to retrieve lost
Suppose I have a text file that says: This file has plain text Now,
We have a command line exe that takes input from a text file and
Supose i have (A,B) (A,C) (A,D) (B,C) (B,D) (C,D) (D,E) in a text file.
I run across this problem frequently suppose I have a text file that I
I have a text file that is almost sometimes 5 mb large. What I

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.