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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:23:26+00:00 2026-05-28T02:23:26+00:00

The Vector find function can search an inserted value even if you try and

  • 0

The Vector find function can search an inserted value even if you try and find by providing substring . Is this same in case of the keys of a map ?

   int main()
   { 
    vector<string> v;
    v.push_back("text");
    v.push_back("[[text");
    v.push_back("text");

    for (unsigned i = 0; i < v.size(); i++)
     {
       if (v[i].find("[[") == 0)
       {
         v[i].append("]]");
       }
     }
  }

Here it finds “[[text” and makes it “[[text]]” .

I tried it in map but code crashes on run time ,. I am using Dev c++

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

      m.insert(pair< string, string>("4-2"," 61-7" ));
      m.insert(pair< string, string>("5-2"," 61-7" ));

     multimap<string, string>::iterator it4;
     multimap<string, string>::iterator it5;
    for ( it4 = m.begin(); it4 !=m.end(); it4++)
    {
        if (m.find("5-") == 0)
        it5=it4;      
    }
    cout << " result of 5 search is" << (*it5).first << ", " << (*it5).second <<endl;
    m.clear();
   getchar();

 }
  • 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-28T02:23:27+00:00Added an answer on May 28, 2026 at 2:23 am

    (Sample correct code on ideone)

    The error is that this line

    if (m.find("5-") == 0)
    

    will never succeed. You maybe be surprised at this. m.find("5-") searches through the entire map looking for an entry whose key is exactly equal to “5-“. Your keys are “4-2” and “5-2”.

    Do you wish to find keys which contain the substring “5-“? Then you need something like

    it4->first.find("5-"); // check if the key string at this entry contains "5-"
    

    I think you want a loop like this:

    multimap<string, string>::iterator it4;
    for ( it4 = m.begin(); it4 !=m.end(); it4++)
    {
        if (it4->first.find("5-") != string :: pos)
                cout << " result of 5 search is" << it4->first << ", " << it4->second <<endl;      
    }
    

    As others have pointed out, you are not interested in the the find method of vector or map. You are interested in the find method of string – this is quite different. The title of your question is a little misleading as a result (unintentionally).

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

Sidebar

Related Questions

I can't find bug in this code In function `BinaryCode::decode(std::string)': undefined reference to `BinaryCode::m_vecStr'
I have searched quite thoroughly on this but can't seem to find an answer.
I can't find what I'm doing wrong here. The function eta does what I
I can look for the position of a value, i.e. 45, in a vector
When I'm writing a function in a template class how can I find out
I want to find in a vector of Object pointers for a matching object.
I find long sequences of standard includes annoying: #include <vector> #include <string> #include <sstream>
I want to find the first item in a sorted vector that has a
I have some numbers stored in a std::vector<int> . I want to find which
vector<vector<string> > test for example. g++, you can do test.reserve(10); test[0] = othervector; test[9]

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.