Jump to content
  • Advertisement
Sign in to follow this  
TommySauder

Accelerated C++ question

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 typed

using 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by TommySauder
is 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!