954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Vector of strings (warnings) ? ?

I have some kinda problem each time i create a vector of strings. There is no error if I create vectors of other data types such as int, double, etc. Though there's no error...but there's warnings...and sometimes the program hangs if i do sortings. Here's an (without sorting but still getting warnings) example:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() 
{
	vector<string> values(5);
	values.push_back("dog");
	values.push_back("cat");
	values.push_back("bag");
	values.push_back("box");
	values.push_back("boy");
	
	for(int i = 0; i < values.size(); i++ )
	{
		cout << values[i] << " ";
	}

	return 0; 
}


This is the message in the build tab:

Compiling...
testSortString.cpp
C:\Documents and Settings\Jason\Desktop\testSortString\testSortString.cpp(24) : warning C4786: 'std::reverse_iterator,std::allocator > const *,std::basic_string,std::all
ocator >,std::basic_string,std::allocator > const &,std::basic_string,std::allocator > const *,int>' : identifier was truncated to '255' characters in the debug information
C:\Documents and Settings\Jason\Desktop\testSortString\testSortString.cpp(24) : warning C4786: 'std::reverse_iterator,std::allocator > *,std::basic_string,std::allocator
>,std::basic_string,std::allocator > &,std::basic_string,std::allocator > *,int>' : identifier was truncated to '255' characters in the debug information
i:\microsoft visual studio\vc98\include\vector(47) : warning C4786: 'std::vector,std::allocator >,std::allocator,std::allocator > > >::vector,std::allocator >,std::allocator,std::allocator > > >' : identifier was truncated to '255' characters in the debug information
i:\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector,std::allocator >,std::allocator,std::allocator > > >::~vector,std::allocator >,std::allocator,std::allocator > > >' : identifier was truncated to '255' characters in the debug information
Linking...

testSortString.exe - 0 error(s), 4 warning(s)

Hope you guys enlighten me....thanks in advance....

j1979c
Light Poster
42 posts since Sep 2005
Reputation Points: 13
Solved Threads: 1
 

You must be using visual studio 6. You can disable the warning with a pragma statement.

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

DEV C++ doesn't give these warnings.....but what does these warning signify??

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 
You must be using visual studio 6. You can disable the warning with a pragma statement.

Yup, I'm using visual studio 6.0. Just downloaded the service pack 6. Browsed through the error listing in MSDN, where they show some errors solved by including pragma statements. But in their example is something to do with indentifiers being too long. Guess I need to learn how to use pragma statements in my c++.
Anyway, thanks for the reply and help. :cheesy:

j1979c
Light Poster
42 posts since Sep 2005
Reputation Points: 13
Solved Threads: 1
 
DEV C++ doesn't give these warnings.....but what does these warning signify??

Ooops, one thing I missed in the posting. I'm using Visual Studio 6.0. Sorry guyz. Thanks for replying though.. :)

j1979c
Light Poster
42 posts since Sep 2005
Reputation Points: 13
Solved Threads: 1
 
But in their example is something to do with indentifiers being too long. :cheesy:



Yes, there is an issue with vs 6 where it complains about templates that generate identifiers longer than 246 characters. I think you simply put:
#pragma warning(disable: 4786) at the top of code. See #4 here: http://www.mip.sdu.dk/ipl98/unofficial/visualc/tips_and_tricks.htm

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 
Yes, there is an issue with vs 6 where it complains about templates that generate identifiers longer than 246 characters. I think you simply put: #pragma warning(disable: 4786) at the top of code. See #4 here: http://www.mip.sdu.dk/ipl98/unofficial/visualc/tips_and_tricks.htm

Yeah, found that out today....that I need to put the#pragma warning(disable: 4786)

before include statements that are usually declared at the top.
I wonder if that still happens if I install the latest service pack 6....I'll check it out then.

Anyway...thanks to you guyz for being so helpful. This is the best forum I've ever been in......guyz/gals in here just know their stuff....beats having bad lecturers in college. Daniweb and MSDN is the best guide! :mrgreen:

j1979c
Light Poster
42 posts since Sep 2005
Reputation Points: 13
Solved Threads: 1
 

I don't think the service pack helps. I know that later versions of Visual Studio (2003), etc. do not have this problem.

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

I have some kinda problem each time i create a vector of strings. There is no error if I create vectors of other data types such as int, double, etc. Though there's no error...but there's warnings...and sometimes the program hangs if i do sortings. Here's an (without sorting but still getting warnings) example:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() 
{
	vector<string> values(5);
	values.push_back("dog");
	values.push_back("cat");
	values.push_back("bag");
	values.push_back("box");
	values.push_back("boy");
	
	for(int i = 0; i < values.size(); i++ )
	{
		cout << values[i] << " ";
	}

	return 0; 
}

This is the message in the build tab:

Compiling... testSortString.cpp C:\Documents and Settings\Jason\Desktop\testSortString\testSortString.cpp(24) : warning C4786: 'std::reverse_iterator,std::allocator > const *,std::basic_string,std::all ocator >,std::basic_string,std::allocator > const &,std::basic_string,std::allocator > const *,int>' : identifier was truncated to '255' characters in the debug information C:\Documents and Settings\Jason\Desktop\testSortString\testSortString.cpp(24) : warning C4786: 'std::reverse_iterator,std::allocator > *,std::basic_string,std::allocator >,std::basic_string,std::allocator > &,std::basic_string,std::allocator > *,int>' : identifier was truncated to '255' characters in the debug information i:\microsoft visual studio\vc98\include\vector(47) : warning C4786: 'std::vector,std::allocator >,std::allocator,std::allocator > > >::vector,std::allocator >,std::allocator,std::allocator > > >' : identifier was truncated to '255' characters in the debug information i:\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector,std::allocator >,std::allocator,std::allocator > > >::~vector,std::allocator >,std::allocator,std::allocator > > >' : identifier was truncated to '255' characters in the debug information Linking...

testSortString.exe - 0 error(s), 4 warning(s)

Hope you guys enlighten me....thanks in advance....

Just small remark about the code given above:
As a result of the declaration you obtain an array of 5 strings, which are undefined. The following lines of code (with push_back methods) push back :)) the NEW elements of array. Summarizing,
you obtain an array of 10 elements where the first five are undefined and the last five are dog, cat, ...

With best wishes,
Borys

borlys
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You