STL <map> question?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

STL <map> question?

 
0
  #1
Aug 27th, 2005
Hello ladies and gents,

Im reading about working with maps and there is small programm example shown in this chapter. Now, when I write this code into the MS VC C++ compiler and compile the code, I get like over 90 warnings, however, when pressing compile again, they all are gone

  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. typedef map<string, int, less<string> > maptype;
  10. maptype M;
  11.  
  12. M["Jan"] = 1234;
  13. M["Piet"] = 9999;
  14. M["Piet"] = 3456;
  15. M["Klaas"] = 5678;
  16.  
  17. for(maptype::iterator i = M.begin(); i != M.end(); ++i)
  18. cout<< (*i).first <<" "<< (*i).second <<endl;
  19.  
  20. cout<<"Press any key to continue!\n";
  21. cin.get();
  22.  
  23. return 0;
  24. }

Some examples of warning messages:
  1. main.cpp
  2. c:\program files\microsoft visual studio\vc98\include\xtree(120) : warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,
  3. int>,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<int> >::_Kfn,std::less<std::basic_string<char,std::char_traits<cha
  4. r>,std::allocator<char> > >,std::allocator<int> >' : identifier was truncated to '255' characters in the debug information
  5. c:\program files\microsoft visual studio\vc98\include\map(46) : see reference to class template instantiation 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<std::basic_string<char,std::char_traits<
  6. char>,std::allocator<char> > const ,int>,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<int> >::_Kfn,std::less<std::ba
  7. sic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<int> >' being compiled
  8. C:\Program Files\Microsoft Visual Studio\MyProjects\LAVbBoek\main.cpp(12) : see reference to class template instantiation 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int,std::less<std::basic_string<char,std
  9. ::char_traits<char>,std::allocator<char> > >,std::allocator<int> >' being compiled

Questions are:

1) What is causing these warnings the first time I compile?
2) How can I make sure that these warnings aren't shown from the first time I compile the code?
3) Why do those warnings don't appear the second time I compile this code?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,646
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 721
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: STL <map> question?

 
0
  #2
Aug 27th, 2005
>1) What is causing these warnings the first time I compile?
The complete identifier is saved for debugging purposes when you compile in debug mode. However, because the internal identifier for templates can be ridiculously long, and the compiler only allows a length of 255 characters, everything after 255 characters has been cut off. The warning simply notifies you of that, and can be safely ignored.

>2) How can I make sure that these warnings aren't shown from the first time I compile the code?
Compile in release mode, or disable the warning with a pragma:
  1. #pragma warning(disable:4786)
>3) Why do those warnings don't appear the second time I compile this code?
Probably because no changes were made to the source, so the file wasn't actually compiled because the current compilation was up to date.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: STL <map> question?

 
0
  #3
Aug 27th, 2005
Thanks Narue
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: STL <map> question?

 
0
  #4
Aug 27th, 2005
Also,

I think some of the warning messages go away with a newer version of visual studio (looks like 6.0/98 based on the paths in your warnings...)
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: STL <map> question?

 
0
  #6
Aug 28th, 2005
Thanks for the additional information gentlemen :!:

Ive got another question and alltough it's not related to <map>, it is related towards STL.

There's a program shown in wich the uses of find_first_of and find_end are explained, now, I understand what find_first_of is doing, but can't figure out what the actual function of find_end is

  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a[10] = {3, 2, 5, 7, 5, 8, 7, 5, 8, 5},
  9. b[2] = {5, 8}, *p1, *p2;
  10.  
  11. p1 = find_first_of(a, a + 10, b, b + 2);
  12. p2 = find_end(a, a + 10, b, b + 2);
  13.  
  14. cout<< p1 - a <<" "<< p2 - a <<endl;
  15.  
  16. cout<<"Press any key to continue!\n";
  17. cin.get();
  18.  
  19. return 0;
  20. }

Output: 2 7

I understand where 2 comes from because comparing a[5] with b[5] puts it on the second place of a, starting from 0.

But, how does 7 becomes the output for find_end, I don't understand, is it also a position that is determined

The explanation that is given isn't really clear and doesn't really make sense, could someone explain what find_end actually does
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,646
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 721
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: STL <map> question?

 
0
  #7
Aug 28th, 2005
>could someone explain what find_end actually does
find_end is actually the reverse of search. search finds the first occurance of the second range in the first range, and find_end finds the last occurance of the second range in the first range. find_end is admittedly poorly named. This example may make more sense:
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a[10] = {3, 2, 5, 7, 5, 8, 7, 5, 8, 5},
  9. b[2] = {5, 8}, *p1, *p2;
  10.  
  11. p1 = search(a, a + 10, b, b + 2);
  12. p2 = find_end(a, a + 10, b, b + 2);
  13.  
  14. cout<< p1 - a <<" "<< p2 - a <<endl;
  15.  
  16. return 0;
  17. }
search looks for the first occurance of {5, 8}, which is at index 4. find_end does the opposite and looks for the last occurance of {5, 8}, which is at index 7.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: STL <map> question?

 
0
  #8
Aug 28th, 2005
Ah, ok, I understand, I changed the last 8 into 9 and it gave me four as result for 'p2 - a'.

Thanks Narue :!:
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,542
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 172
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: STL <map> question?

 
0
  #9
Aug 30th, 2005
JoBe, that looks like interesting code you doing! Is that STL stuff or what?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC