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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:01:43+00:00 2026-05-18T11:01:43+00:00

How to declare std map constants i.e., int a[10] = { 1, 2, 3

  • 0

How to declare std map constants i.e.,

int a[10] = { 1, 2, 3 ,4 };
std::map <int, int> MapType[5] = { };
int main()
{
}

In the about snippet it is possible to give values 1,2,3,4 to integer array a, similarly how to declare some constant MapType values instead of adding values inside main() function.

  • 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-18T11:01:44+00:00Added an answer on May 18, 2026 at 11:01 am

    UPDATE: with C++11 onwards you can…

    std::map<int, int> my_map{ {1, 5}, {2, 15}, {-3, 17} };
    

    …or similar, where each pair of values – e.g. {1, 5} – encodes a key – 1 – and a mapped-to value – 5. The same works for unordered_map (a hash table version) too.


    Using just the C++03 Standard routines, consider:

    #include <iostream>
    #include <map>
    
    typedef std::map<int, std::string> Map;
    
    const Map::value_type x[] = { std::make_pair(3, "three"),
                                  std::make_pair(6, "six"),
                                  std::make_pair(-2, "minus two"), 
                                  std::make_pair(4, "four") };
    
    const Map m(x, x + sizeof x / sizeof x[0]);
    
    int main()
    {
        // print it out to show it works...
        for (Map::const_iterator i = m.begin();
                i != m.end(); ++i)
            std::cout << i->first << " -> " << i->second << '\n';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I declare a temporary auto deleted character buffer using std::auto_ptr<char> buffer(new char[n]); then
I declare a static char array, then I pass it to a function. How
Given the following: declare @a table ( pkid int, value int ) declare @b
Declare @BadDecimal varchar(5) Set @BadDecimal = '4.5' Declare @GoodDecimal Decimal Set @GoodDecimal = @BadDecimal
I declare a variable for a 64 bit counter as : long long call_count;
Why does Visual Studio declare new classes as private in C#? I almost always
If you declare variables of type byte or short and attempt to perform arithmetic
In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN
Is there anyway to declare an object of a class before the class is
When you attempt to declare an unsigned variable in C#.NET with a value outside

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.