944,153 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4956
  • C++ RSS
Aug 27th, 2005
0

STL <map> question?

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Aug 27th, 2005
0

Re: STL <map> question?

>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:
C++ Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Aug 27th, 2005
0

Re: STL <map> question?

Thanks Narue
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Aug 27th, 2005
0

Re: STL <map> question?

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...)
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Aug 27th, 2005
0

Re: STL <map> question?

use STLFilt
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Aug 28th, 2005
0

Re: STL <map> question?

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

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Aug 28th, 2005
0

Re: STL <map> question?

>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:
C++ Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Aug 28th, 2005
0

Re: STL <map> question?

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

Thanks Narue :!:
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Aug 30th, 2005
0

Re: STL <map> question?

JoBe, that looks like interesting code you doing! Is that STL stuff or what?
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: PLS help me do this program..
Next Thread in C++ Forum Timeline: Midi Library





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC