Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

std::map

Hi,
I'm trying to use a very simple sample from a Herbert Schildt's book using the stl's map, but it doesnt work. Im using MSDeV Studio 6 and when I compile it gives a lot of hieroglific warnings. Is it something to do with the Micrososft implemetation of STL?

The sample is:

#include  <iostream>
#include  <map>
using namespace std;
int main()
{
  map<char, int> m;
  int i;
  for(i = 0; i <26 ; i++)
    m.insert(pair<char,int('A'+i,65+i));

  char ch;
  cout << "Enter key: ";
  cin >> ch;
 
  map<char, int>::iterator p;
  p = m.find(ch);
  if (p != m.end())
    cout << "Its ASCII value is "  << p->second;
 else
    cout << "key not in map.\n";
  return 0;
}
0
nogueira
Asked:
nogueira
  • 4
  • 3
  • 2
1 Solution
 
nietodCommented:
>> Is it something to do with the
>> Micrososft implemetation of STL?
Sometimes this is the problem, but rarely.  More likely itis a mistake in your code.

>>  m.insert(pair<char,int('A'+i,65+i));
There is no ">" at the end of the "pair<"

If that doesn't fix the problem, lost the error messages you are getting.
0
 
KangaRooCommented:
Error messages on templates can be intimidating. If nietods suggestion does not work, try to comment out the major part of the code (leaving only the map's declaration) and uncomment parts until the error reappears.
0
 
nogueiraAuthor Commented:
well in fact it misses a > in the sample I've posted but thats an error I've made when I 'pasted' in here the code. the warnings that keep appearing me are of the type :

warning C4786: 'std::reverse_bidirectional_iterator<std::_Tree<char,s ...'

if it helps...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
KangaRooCommented:
Could you give a bit more of the warning message?
0
 
nogueiraAuthor Commented:
Adjusted points from 50 to 75
0
 
nogueiraAuthor Commented:
These are the warnings that appear in the MSDevStudio 6 debug window:

--------------------Configuration: mapTeste - Win32 Debug--------------------
Compiling...
MapTeste.cpp
h:\geopilot\src\testes\mapteste\mapteste.cpp(52) : warning C4786: 'std::reverse_bidirectional_iterator<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::it
erator,std::pair<char const ,int>,std::pair<char const ,int> &,std::pair<char const ,int> *,int>' : identifier was truncated to '255' characters in the debug information
h:\geopilot\src\testes\mapteste\mapteste.cpp(52) : warning C4786: 'std::reverse_bidirectional_iterator<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::co
nst_iterator,std::pair<char const ,int>,std::pair<char const ,int> const &,std::pair<char const ,int> const *,int>' : identifier was truncated to '255' characters in the debug information
h:\geopilot\src\testes\mapteste\mapteste.cpp(52) : warning C4786: 'std::pair<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::iterator,std::_Tree<char,std
::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::iterator>' : identifier was truncated to '255' characters in the debug information
h:\geopilot\src\testes\mapteste\mapteste.cpp(52) : warning C4786: 'std::pair<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::const_iterator,std::_Tree<ch
ar,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::const_iterator>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\xtree(182) : warning C4786: 'std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::~_Tree<char,std::pair<
char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\xtree(162) : warning C4786: 'std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::_Tree<char,std::pair<c
har const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__ehhandler$?insert@?$_Tree@DU?$pair@$$CBDH@std@@U_Kfn@?$map@DHU?$less@D@std@@V?$allocator@H@2@@2@U?$less@D@2@V?$allocator@H@2@@std@@QAE?AU?$pair@Viterator@?$_Tree@DU
?$pair@$$CBDH@std@@U_Kfn@?$map@DHU?$less@D@std@@V?$allocator@H@2@@2@U?$less@D@2@V?$allocator@H@2@@std@@_N@2@ABU?$pair@$$CBDH@2@@Z' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__unwindfunclet$?insert@?$_Tree@DU?$pair@$$CBDH@std@@U_Kfn@?$map@DHU?$less@D@std@@V?$allocator@H@2@@2@U?$less@D@2@V?$allocator@H@2@@std@@QAE?AU?$pair@Viterator@?$_Tre
e@DU?$pair@$$CBDH@std@@U_Kfn@?$map@DHU?$less@D@std@@V?$allocator@H@2@@2@U?$less@D@2@V?$allocator@H@2@@std@@_N@2@ABU?$pair@$$CBDH@2@@Z$0' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std::pair<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::iterator,bo
ol>::pair<std::_Tree<char,std::pair<char const ,int>,std::map<char,int,std::less<char>,std::allocator<int> >::_Kfn,std::less<char>,std::allocator<int> >::iterator,bool>' : identifier was truncated to '255' characters in the debug information
Linking...

mapTeste.exe - 0 error(s), 9 warning(s)
0
 
KangaRooCommented:
The warning message is clear enough: "identifier was truncated to '255' characters in the debug information"
The compiler stores information on the C++ source code in the compiled object files (code, identifier names and type), which is used by the debugger to give you readable names and type information. You will probably loose some debugging comfort after this message.
There maybe some compiler option to expand the possible size of debug identifier names, or a switch or pragma to diable this specific warning, something like
#pragma warn -C4786
I don't have VC but nietod does...
0
 
nogueiraAuthor Commented:
Thanks kangaroo
0
 
nietodCommented:
Sory for not getting back.  I've been unable to connect reliably to EE all morning.  I've been getting the notificatin e-mails though, an been very impatient to see what was going on here.

As kangroo said, that message is simply a warning and can be ignored--eveyone who uses STL gets it.  

There is no way to expand limit that has been reached, but there doesn't seem to be need either.  Instead you can prevent the warning from printing.

But another problem has creeped in.  I don't have access to VC right now, and I don't remember the exact syntax you need to to dissable the warning.  It is done with a #pragma of some sort.   You can look in the help under #pragma.  If you can't find it, post a message here and I'll be able to look it up.  (In a few hours.)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now