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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:36:06+00:00 2026-05-25T10:36:06+00:00

How can I use a 2D char array with a map in C++. I

  • 0

How can I use a 2D char array with a map in C++. I want to do this:

map<char[50][50],int>M;

char brr[50][50];
//some operation here on the array
int aa=1;

if(M.find(brr)==M.end())
{
     M[brr]=aa;
     aa+=1;
}

what am I doing wrong?

EDIT:

I’ve just found another way. This way I can achieve what I stated in my question. Instead of using the 2d array I’m just gonna convert it into a string and use it. It’ll still yield the same result:

map<string,int>M;

char brr[50][50];
//some operation here on the array
int aa=1,i,j;

string ss="";

for(i=0;i<50;i++)
{
     for(j=0;j<50;j++)
     {
         ss+=brr[i][j];
     }
}

if(M.find(ss)==M.end())
{
     M[ss]=aa;
     aa+=1;
}
  • 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-25T10:36:07+00:00Added an answer on May 25, 2026 at 10:36 am

    You can’t. Arrays can’t be assigned to (i.e. you can’t do brr = XXX; in your example), and this is a requirement of the key type of a std::map. Also, the key needs to have a strict weak ordering defined on it (i.e. it needs operator< or a comparator function).

    You could consider wrapping your array in a class, defining an appropriate operator <, and then using this as the key type.

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

Sidebar

Related Questions

How can I use sed to replace this line char * path_list_[1] = {
In c/c++ some people use c-styled strings like: char *str = This is a
I want to copy the content in the string to char array. Can I
I have a char array which contains some value . I want to copy
You can use templates to find the length of an array. template<typename T, size_t
Can the application use set same char in the XON and XOFF? If yes,
my question is simple: Should I use array of char eg: char *buf, buf2[MAX_STRING_LENGTH]
From this question, I know you can use SecKeychainFindGenericPassword without a username value. It
This may be a slightly theoretical question. I have a char array of bytes
I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string

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.