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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:22:13+00:00 2026-06-03T07:22:13+00:00

I am stuck on trying to figure out how to insert a vector for

  • 0

I am stuck on trying to figure out how to insert a vector for a value in a map. For example:

#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main()

{

    map <int, vector<int> > mymap;   

    mymap.insert(pair<int, vector<int> > (10, #put something here#));

    return 0;
}

I don’t know what syntax to use insert a vector for value. I tried {1,2}, but that failed. What syntax should I use?

Everything works if I declare a vector in advance and give it a name, but I don’t want to do that, as I want to have a map with a lot of vectors.

Thank You in Advance

  • 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-03T07:22:15+00:00Added an answer on June 3, 2026 at 7:22 am

    Basically your question is not about inserting std::vector into a std::map. Your question is how can you easily create an anonymous std::vector with arbitrary initial element values.

    In ISO C++03, you can’t. C++11 allows using initialization lists for this, however.

    If you are stuck with a C++03 compiler, you possibly could create a helper function to return a vector with specified elements:

    std::vector<int> make_vector(int a, int b)
    {
        std::vector<int> v;
        v.push_back(a);
        v.push_back(b);
        return v;
    }
    

    If the vectors you’re inserting are of different sizes, you could use a variadic function, although doing so would require that you either pass along the number of elements or have a reserved sentinel value.

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

Sidebar

Related Questions

I'm stuck trying to figure out if this is possible. Using the blog example
I've been stuck trying to figure out why a counter cache on my (parent)
I'm trying to automate file comment headers. I'm stuck trying to figure out how
I am stuck trying to figure out how to initiate a WSDL connection with
Im stuck, been trying to figure this out for 2 hours now. I have
I'm stuck at the moment trying to figure out a method of inserting into
I was trying to figure out how to work with SQLite database using python,
Im stuck trying to figure out how to pull the information from my pre-populated
I'm stuck again trying to figure out how to out the button clicked to
I am stuck trying to figure out how to alter my collision detection to

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.