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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:45:34+00:00 2026-06-13T08:45:34+00:00

I encountered a problem when tried compiling the following code: #include <iostream> #include <cstdio>

  • 0

I encountered a problem when tried compiling the following code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

map<char, int> mapDial;

mapDial['A'] = 2;

int main()
{

  cout << mapDial['A'] << endl;
  return 0;
}

The compiler gave me a error: ‘mapDial’ does not name a type error. I am new to c++ and really don’t know what is going on here. Can anyone here help me to solve this? Thanks!!

  • 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-13T08:45:35+00:00Added an answer on June 13, 2026 at 8:45 am

    You cannot execute arbitrary expressions at global scope, so

    mapDial['A'] = 2;
    

    is illegal. If you have C++11, you can do

    map<char, int> mapDial {
        { 'A', 2 }
    };
    

    But if you don’t, you’ll have to call an initialisation function from main to set it up the way you want it. You can also look into the constructor of map that takes an iterator, and use that with an array in a function to initialise the map, e.g.

    map<char, int> initMap() {
        static std::pair<char, int> data[] = {
            std::pair<char, int>('A', 2)
        };
    
        return map<char, int>(data, data + sizeof(data) / sizeof(*data));
    }
    
    map<char, int> mapDial = initMap();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've encountered a problem. I have a code which should read the following text
When I tried compiling my app for OS 3 I encountered an the following
I tried to create a simple web app using ICEfaces and encountered a problem.
I encountered a problem when I tried to use java from matlab. I read
i encountered a problem using the apache commons-net telnet api, and hope you can
I encountered a problem dealing with UTF-8, XML and Perl. The following is the
I have encountered this solution for a problem I tried to solve (uncheck radio
I encountered a problem here. I'm using C++ multiset. This is the test file.
I had encountered strange problem while construct a unordeed_set<tuple<int,int>> . I had tried VC++8,
I encountered a problem when I tried to implement the ServiceKnownType example from MSDN.

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.