Thread: vector<string> warnings

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    596

    vector<string> warnings

    This program serves no purpose except to start learning how to use some STL classes.

    It compiles & runs as expected, but with some ugly & incomprehensible warnings (actually 5 copies of the same warning). What do they mean, and why 5 of them?

    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    int main(){
    	int i;
    	vector<string> list;
    	string myString("seven");
        list.push_back("six");
        list.push_back("one");
        list.push_back("two");
        list.push_back("three");
        list.push_back("four");
        list.push_back("five");
        for(i=0;i<6;i++)
            cout << (list.at(i)).at(0) << endl;
    	cout << myString << endl;
    	vector<string> list2 (6, myString);
    	for(i=0;i<list2.size();i++)
    		cout << list2.at(i) << endl;
    
        return 0;
    }
    --------------------Configuration: vector2 - Win32 Debug--------------------
    Compiling...
    vector2.cpp
    E:\cs71010\scrap\vector2\vector2.cpp(25) : 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>,st d::allocator<char> >,std::basic_string<char
    ,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
    E:\cs71010\scrap\vector2\vector2.cpp(25) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >,std::basic_string<char,std::
    char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<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(47) : warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<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_trai ts<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

    vector2.obj - 0 error(s), 5 warning(s)

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://msdn.microsoft.com/library/de...err46xx_49.asp

    Perhaps search the board for C4786 as well.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Oops. Sorry about the spam.

    So Microsoft's compiler is complaining about the length of the name of Microsoft's template class?

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Anyway, what is all that stuff?

    How did vector<string> grow to
    std::reverse_iterator<std::basic_string<char,std:: char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >,std::basic_string<char
    ,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > const *,int>'
    Actually the 5 identifiers are not all the same. I think the last 3 are the same; the first 2 are different.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    std::string is actually a typedef for a concrete instantiation of the template basic_string.

    The standard defines basic_string as
    Code:
    template < typename CharacterType, typename CharacterTraits, typename Allocator >
    CharacterType is the data type that makes up a single character. Usually this will be char or wchar_t, but in theory you can use anything.
    CharacterTraits defines some basic properties of the character type, like how they are to be compared for equality. This parameter defaults to std::char_traits<CharacterType>.
    Allocator is responsible for memory allocation. This defaults to std::allocator<CharacterType>.

    std::string is defined as such:
    Code:
    typedef basic_string<char> string;
    ... using the defaults for the other two parameters.

    Supplying the full template substitution, complete with namespace prefixes, this is the resulting type:
    Code:
    std::basic_string< char, std::char_traits< char >, std::allocator< char > >
    That's not too bad. Now, vector is a template, too. vector<string> expands to this:
    Code:
    std::vector< std::string, std::allocator< std::string > >
    and substituting std::string:
    Code:
    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
          >
        >
      >
    >
    That alone is enough to break the limit on identifier length that VC++6 imposed.

    But there's also the implementation details of std::vector, such as the instantiation of
    Code:
    std::reverse_iterator<
      typename Iterator,
      typename ValueType = std::iterator_traits<Iterator>::value_type,
      typename Reference = std::iterator_traits<Iterator>::reference,
      typename Pointer = std::iterator_traits<Iterator>::pointer,
      typename Difference = std::iterator_traits<Iterator>::difference_type
    >
    with Iterator = std::string const * (expanded, of course).
    Last edited by CornedBee; 10-27-2005 at 02:59 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Thanks, CornedBee, but that's pretty baffling. Can you suggest any websites where I can find explanations and examples of how those template arguments other than <class Type> are actually used and what they do? (Hopefully something clearer than I can find in the MSDN Library.)

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You'd be better off ignoring them for now. It's entirely possible that you'll never need to consider them in your own code.
    My best code is written with the delete key.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you do want to know, I'd recommend a book, like "The Standard Template Library" by Nicolai Josutti (name taken from memory, might be wrong).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Thanks, I will look at that.

    BTW, for anyone who's interested, it's Nicolai M. Josuttis, and the isbn is 0-201-37926-0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Warnings when using vector of vector
    By Boksha in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2008, 01:54 PM
  2. Compilers and warnings
    By rogster001 in forum C Programming
    Replies: 6
    Last Post: 03-26-2008, 05:16 AM
  3. Replies: 9
    Last Post: 03-14-2008, 09:55 AM
  4. Vector<string> warnings
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2002, 04:35 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM