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 :?:

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

using namespace std;

int main()
{
	typedef map<string, int, less<string> > maptype;
	maptype M;

	M["Jan"]   = 1234;
	M["Piet"]  = 9999;
	M["Piet"]  = 3456;
	M["Klaas"] = 5678;

	for(maptype::iterator i = M.begin(); i != M.end(); ++i)
		cout<< (*i).first <<" "<< (*i).second <<endl;

	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

Some examples of warning messages:

main.cpp
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 ,
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
r>,std::allocator<char> > >,std::allocator<int> >' : identifier was truncated to '255' characters in the debug information
        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<
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
sic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<int> >' being compiled
        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
::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?

Recommended Answers

All 8 Replies

>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:

#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.

Thanks Narue ;)

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...)

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 :confused:

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int a[10] = {3, 2, 5, 7, 5, 8, 7, 5, 8, 5},
		b[2] = {5, 8}, *p1, *p2;

	p1 = find_first_of(a, a + 10, b, b + 2);
	p2 = find_end(a, a + 10, b, b + 2);

	cout<< p1 - a <<" "<< p2 - a <<endl;
	
	cout<<"Press any key to continue!\n";
	cin.get();

	return 0;
}

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 :?:

>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:

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
  int a[10] = {3, 2, 5, 7, 5, 8, 7, 5, 8, 5},
    b[2] = {5, 8}, *p1, *p2;

  p1 = search(a, a + 10, b, b + 2);
  p2 = find_end(a, a + 10, b, b + 2);

  cout<< p1 - a <<" "<< p2 - a <<endl;

  return 0;
}

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.

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

Thanks Narue :!:

JoBe, that looks like interesting code you doing! Is that STL stuff or what?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.