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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:13:37+00:00 2026-05-17T03:13:37+00:00

I need to use STL C++ map to store key value pairs. I need

  • 0

I need to use STL C++ map to store key value pairs.
I need to store more than one data information in stl map.
e.g

Need to store DataType,Data and its behavior as(in param/outparam) all in string format.
But map always use key value pair

so if I
store it like

std::map<map<"int","50",>"behavior">. 

But always it sorts the the data on basis of keys which I dont want. If I use like ..

pair<string, pair<string,string> >;
pair<string, pair<string,string>>("int",("100","in"));

This prompts compile time error!

error C2664: ‘std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)’ : cannot convert parameter 1 from ‘const char *’ to ‘const std::pair<_Ty1,_Ty2> &’

What should be the exact solution of the above problem?

Regards

  • 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-17T03:13:38+00:00Added an answer on May 17, 2026 at 3:13 am

    If you don’t want ordering, don’t use ordered containers like map or set. You could achieve what you’re looking for using a class and a vector. The sorted nature of std::map is what makes it efficient to lookup by key. If you want/need unsorted and more hash like behavior for lookups, look at Boost unordered containers. Note that this doesn’t guarantee the order in is going to be the order out. I’m assuming you want to preserve the order of the types your putting in the container, the example below will do that.

    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    class DataBehavior
    {
    public:
        DataBehavior(const string &type, 
                     const string &data,
                     const string &behavior)
            :type(type), data(data), behavior(behavior)
        {
        }
    
        const string &getType() const     { return type; }
        const string &getData() const     { return data; }
        const string &getBehavior() const { return behavior; }
    
    private:
        string type;
        string data;
        string behavior;
    };
    
    typedef vector<DataBehavior> Ctr;
    
    int main (int argc, char *argv[])
    {
        Ctr ctr;
        ctr.push_back(DataBehavior("int",    "50", "behavior"));
        ctr.push_back(DataBehavior("int",    "80", "behavior"));
        ctr.push_back(DataBehavior("string", "25", "behavior2"));
    
        for (Ctr::const_iterator it = ctr.begin(); it != ctr.end(); ++it)
        {
            cout << "Type: " << it->getType() << "  " 
                 << "Data: " << it->getData() << "  "
                 << "Behavior: " << it->getBehavior() << "\n";
        }
        return 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a VBA map object similar to C++ STL map class for use
I need to store a graph for the map of a game inside a
What is the alternative if I need to use a reference, and the data
I need to use a spatial 2d map for my application. The map usually
I use visual studio 2010 and its stl implementation is from dinkumware I noticed
Can a STL map be used for keys of varying sizes? I don't have
I need to create a hash table that has a key as a string,
Should I need to call reset method or anything, when I try to use
I'm currently trying to learn how to effectively use the STL part of c++.
I'm trying to use RAII concepts with an STL container of ofstream objects. For

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.