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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:14:44+00:00 2026-05-24T00:14:44+00:00

The following code supposedly works with VS 2008 but I’m having trouble around line

  • 0

The following code supposedly works with VS 2008 but I’m having trouble around line 53
where:

portMap_.erase(it);

I’m using codeblocks/mingw/gcc 4.xx

#include<iostream>
#include<map>
#include<string>

using namespace std;

//defining a union that is used with newMap_
union uu
{
  char c;
  int i;
} u;

//Lets define two different maps
//The first parameter is key and second value
map<string, int> portMap_;
map<void *, uu> newMap_;

int main()
{
  //first entry in portmap
  portMap_["first"] = 1;

  //example of using the iterator
  map<string, int>::const_iterator it;
  string z = "second";
  it = portMap_.find(z); //not in the map so wont be found
  if(it == portMap_.end())
  {
    portMap_[z] = 22; //add second element
  }

  //Add thrid element directly
  z = "third";
  portMap_[z] = 12345;

  //Add 4th element by insert
  portMap_.insert(pair<string,int>("fourth", 4444));

  //Add 5th element by insert
  portMap_.insert(pair<string,int>("fifth", 5555));


  cout<<"\n** Printing the portmap_ values **"<<endl;
  for(it = portMap_.begin(); it != portMap_.end(); ++it)
    cout<<"Key = "<<it->first<<"   Val = "<<it->second<<endl;

  cout<<"\n** Removing fourth element **"<<endl;
  z = "fourth";
  it = portMap_.find(z);
  portMap_.erase(it);

  cout<<"\n** Printing the portmap_ values **"<<endl;
  for(it = portMap_.begin(); it != portMap_.end(); ++it)
    cout<<"Key = "<<it->first<<"   Val = "<<it->second<<endl;

  //Playing with New Map
  cout<<"\n\nCreating New Map whose key is a void pointer"<<endl;

  uu u_val1, u_val2;
  void *val1, *val2;
  u_val1.i = 70, val1 = &u_val1;
  newMap_[val1]=u_val1;

  val2 = val1;
  map<void *, uu>::const_iterator it_new;
  it_new = newMap_.find(val2);
  if(it_new != newMap_.end())
  {
    u_val2 = it_new->second;
    cout<<"Note that since u_val2 is a union you can print i or c as required"<<endl;
    cout<<"val2 = "<<val2<<"    value.c = "<<u_val2.c<<endl;
    cout<<"val2 = "<<val2<<"    value.i = "<<u_val2.i<<endl;
  }

  return 0;
}

Heres the error:

map_example\map_example.cpp||In function 'int main()':|
map_example\map_example.cpp|51|error: no matching function for call to 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::erase(std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >&)'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_map.h|566|note: candidates are: void std::map<_Key, _Tp, _Compare, _Alloc>::erase(typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char,|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_map.h|581|note:                 typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::size_type std::map<_Key, _Tp, _Compare, _Alloc>::erase(const _Key&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_stri|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_map.h|596|note:                 void std::map<_Key, _Tp, _Compare, _Alloc>::erase(typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator) [with _Key = std::basic_string<char, std::char_traits<char>, std::all|
||=== Build finished: 1 errors, 0 warnings ===|
  • 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-24T00:14:44+00:00Added an answer on May 24, 2026 at 12:14 am

    Try change from map<string, int>::const_iterator it; to map<string, int>::iterator it.

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

Sidebar

Related Questions

I am having a problem. The following code works fine in my local, but
The following code works great in IE, but not in FF or Safari. I
When I set the tintcolor using following code it works self.navigationController.navigationBar.tintColor = [UIColor brownColor];
The following code works differently on 64 bit and on 32 bit which is
So I wrote the following code in linux(Ubuntu) using the emacs text editor it
I am trying to embed a font using the following code that I found
The following code produces an error hr=0x80020005 (wrong type). #import <msi.dll> using namespace WindowsInstaller;
The following code is supposed to make the right 60% of the display red.
I am creating a SMS app the following code is supposed to: check if
Given the following code (it's supposed to write helloworld in a helloworld file, and

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.