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

  • Home
  • SEARCH
  • 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 8398657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:06:20+00:00 2026-06-09T21:06:20+00:00

Sorry for posting the same problem again, but I used the suggested solutions, and

  • 0

Sorry for posting the same problem again, but I used the suggested solutions, and it partially worked…
So I want to clarify the problem:

So:

I defined a vector of maps, like this:

typedef vector<map<string,unsigned int> > myvec;

And a map of vectors (i called it index) like this:

typedef map<string,vector<unsigned int> > index;

Then I did the following:

In my class, called myCoogle, i declared myvec maps_vec;

and I filled it with maps…

In each map there’s a word (string) and a number (unsinged int).

So far so good.

I declared also index the_index;

Now I want to copy all the different words from the_vec to the_index.

The words will be the strings…

And for each vector i will be adding the numbers stored in the vector of maps.

For example:

the_vec has 3 maps.

the 1st has: chicken,1 | person,1 | elevator,5 | is,2 | …

the 2nd has: person,2 | icecream,3 | is,3 | …

the 3rd has: elevator,1 | bear,1 | is,4 | chicken,3 | …

So the_index should look like this:

word,[vector of ints]

chicken[1,0,3]

person,[1,2,0]

elevator[5,0,1]

is[2,3,4]

icecream[0,3,0]

bear[0,0,1]

OK here’s my function:

void Coogle::make_index()
{
    //SCAN THE FIRST MAP
    myvec::iterator myvec_iter;
    map<string,unsigned int>::iterator map_iter;
    index::iterator idx_iter = the_index.begin();
    for(map_iter=maps_vec[0].begin(); map_iter!=maps_vec[0].end(); ++map_iter)
    {
        the_index[map_iter->first].push_back(map_iter->second);
    }


    //SCAN THE OTHER MAPS
    myvec_iter=maps_vec.begin();
    myvec_iter++;
    int i=0; //FILE #
    while(myvec_iter!=maps_vec.end())
    {
        i++;
        for(map_iter=maps_vec[i].begin(); map_iter!=maps_vec[i].end(); ++map_iter)
        {
            string word=map_iter->first;
            cout << "DEALING WITH WORD \"" << word << "\"" << endl;
            index::iterator location;
            location=the_index.find(word);
            if(location!=the_index.end()) //if word found in the index
            {
                cout << "WORD EXISTS!" << endl;
                location->second[i]=map_iter->second;
            }
            else //if not found
            {
                cout << "WORD DOES NOT EXIST! NEW WORD." << endl;
                the_index[word].push_back(map_iter->second);
            }
        }
        cout << endl;
        ++myvec_iter;
    }
}

clarification: FILE# is the maps number… I’m working with files (*.txt files).

Alright so after I scanned the first map, I tried to print the_index and all was fine.
But I get this when trying to print after scanning also the other maps:

the bug

‘Build Successfully’ though.

And this window pops up when I run the program.

So I believe something is wrong with my 2nd ‘for’ loop.

Anyone can help please?

Very sorry for the very long post…

Thank you very much !!!

edit:
If I don’t try to print the_index, the program compiles and runs just fine.
But that’s not enough ofcourse.
But my print function is just alright… here:

void Coogle::print_index() const
{
    index::const_iterator iter;
    for(iter=the_index.begin();iter!=the_index.end();++iter)
    {
        cout << "Word: " << iter->first << endl;
        //cout << "Files number is: " << files_number << endl; //prints: 3
        for(int i=0; i<files_number;i++)
            cout << "file #" << i+1 << ": " << iter->second[i] << " , " << endl;
    }
}

edit:

Here’s a screen shot of printing only 1 map vs printing 3 maps:

1 map vs 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-06-09T21:06:21+00:00Added an answer on June 9, 2026 at 9:06 pm

    Edit: Ok hopefully I finally understand what you’re trying to do.

    typdef myvec::iter vmiter_t;
    typdef map<string,unsigned int>::iter miter_t;
    typdef set<string>::iter siter_t;
    
    set<string> words;
    
    for(vmiter_t vmiter=maps_vec.begin(); vmiter != maps_vec.end(); ++vmiter)
    {
        for(miter_t miter = vmiter->begin(); miter != vmiter->.end(); ++miter)
        {
            words.insert(miter->first);
        }
    }
    
    for (siter_t iter=words.begin(); iter!=words.end(); ++iter){
        const string& word = *iter;
        for(vmiter_t vmiter=maps_vec.begin(); vmiter != maps_vec.end(); ++vmiter)
        {
            map<string,unsigned int>& temp = *vmiter;
            the_index[word].push_back(temp[word]);
        }
    }
    

    It’s hard to tell since you didn’t provide the declaration of your variables (and some of them seem to be misnamed), but I think the problem is the line location->second[i]=map_iter->second;. You are trying to access index i in the vector, but your vector isn’t actually that long.

    Edit: Now that I can tell what you’re actually trying to do, you’re massively overcomplicating things. You don’t need a seperate loop for the other elements at all.

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

Sidebar

Related Questions

First up, sorry for the mega-posting of code but... I have the following DB
(I posted this before anonymously, but then couldn't use the same computer again, so
Sorry for posting such a lowly beginner's question, but I just still don't know
Sorry for posting this question again. I rephrased my question a little bit. I
EDIT: I solved it seconds after posting the question (sorry!) but can't accept an
I am sorry if it seems like I am posting the same question. The
Sorry for posting this but !function is not google-able and I did not find
Sorry to be posting this question. :( But I have spent almost the entire
Hi Sorry for posting a big dump of code but I'm very new at
Sorry about this question but i never worked with SQLite, and i gone through

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.