Solved

std::map

Posted on 2000-03-20
9
523 Views
Last Modified: 2013-12-14
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
Comment
Question by:nogueira
  • 4
  • 3
  • 2
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 75 total points
ID: 2635985
>> 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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2636175
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
 

Author Comment

by:nogueira
ID: 2636299
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2636468
Could you give a bit more of the warning message?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:nogueira
ID: 2636649
Adjusted points from 50 to 75
0
 

Author Comment

by:nogueira
ID: 2636650
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2636731
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
 

Author Comment

by:nogueira
ID: 2636965
Thanks kangaroo
0
 
LVL 22

Expert Comment

by:nietod
ID: 2637191
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now