Public Group

Accelerated C++ question

This topic is 4875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

"Write a program to count how many times each distinct word appears in its input" We're dealing with vectors... and if I type vector<string> words, i come some compiler warnings... and have no idea what to do from there...

Share on other sites
Are you including <vector> and <string>? Did you put a using declaration or directive to bring them in from namespace std? Did you try put std:: in front of vector and string?

Share on other sites
What compiler warnings?

Share on other sites
#include <string>#include <iostream>#include <vector>#include <iomanip>#include <ios>#include <algorithm>// Ask user for words to input, then ask for the program to// count how many times that word was typedusing namespace std;int main(){	// get users name	cout << "Please enter your name: ";	string name;	cin >> name;	cout << "Hello, " << name << "!" << endl;	// create the vector of strings	vector<string> words;	return 0;}

I simplified it to show the warnings...

Here they are:
Compiling...
vectorstring.cpp
C:\Documents and Settings\TJ Sauder\My Documents\C++\Accelerated C++\3\stringsvector\vectorstring.cpp(26) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std
::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters
in the debug information
C:\Documents and Settings\TJ Sauder\My Documents\C++\Accelerated C++\3\stringsvector\vectorstring.cpp(26) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char
_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug info
rmation
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information

Share on other sites
That's just MSVC 6 being a pain in the rear. If at all possible I'd suggest upgrading compilers. If you don't want to do that, then you can ignore C4786's.

Share on other sites
You've just encountered one of the plethora of reasons to abandon MSVC6.0 and move to a more standards-compliant and generally "actually works" compiler.

But if that seems like a bit too much to handle at this point, try placing the preprocessor directive "#pragma warning(disable: 4786)" anywhere near the top of your file to get rid of those particular nasty, useless warnings.

EDIT: Basically, what SiCrane said. :D

Share on other sites
is it free to upgrade compilers? I paid almost an arm and a leg for msvc 6 when I got it :\

Share on other sites
You can usually safely ignore warning C4786. It's just pointing out a limit of compiler when dealing with long identifiers in debug compiles. As the Standard Template Library (vector, algorithm, etc) uses nested templates, the identifiers get rather long.

You can actually turn them off by putting

#pragma warning(disable:4786)

in the source file near the top:)

Edit: too late I see [grin]

Share on other sites
ok thanks, now I'm just wondering if theres an easier way to search through a vector of strings, rather than doing it through a loop...

edit: what do you type if you want to read the end of the vector not knowing how large it is... v[end - 1]? not sure of the correct syntax.

Share on other sites
Quote:
 Original post by TommySauderis it free to upgrade compilers? I paid almost an arm and a leg for msvc 6 when I got it :\
Microsoft offers the Visual C++ 2003 compiler (not IDE) for free. It takes a bit of work to plug it into the VC6 IDE, but it is doable, and instructions are on the net.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• Forum Statistics

• Total Topics
634070
• Total Posts
3015330
×