CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Unhappy Compiling error on my simple STL spell-checker.

    Hi, everyone!

    Here is my simple STL program, it is a spell-checker.
    The program copy every word of text to output
    that is not in the dictionary. I have added all the source
    codes and error messages below. My IDE is VC6.0.


    Source Codes:

    --------
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <fstream>

    using namespace std;

    template <class bidirectional_iterator, class T>
    class nonAssocFinder {
    public:
    nonAssocFinder(bidirectional_iterator begin,
    bidirectional_iterator end) :
    _begin(begin), _end(end) {}

    bool operator() (const T& word) {
    return binary_search(_begin, _end, word); }

    private:
    bidirectional_iterator _begin;
    bidirectional_iterator _end;
    };


    void main()
    {
    typedef vector<string > dict_type;

    ifstream dictFile("dict.txt");
    ifstream wordsFile("words.txt");

    dict_type dictionary;

    copy (istream_iterator<string>(dictFile),
    istream_iterator<string>(),
    back_inserter(dictionary));

    remove_copy_if (
    istream_iterator<string>(wordsFile),
    istream_iterator<string>(),
    ostream_iterator<string>(cout, "\n"),
    nonAssocFinder<dict_type::iterator,
    dict_type::value_type>
    (dictionary.begin(), dictionary.end()));
    }
    --------

    Warning and error messages:
    --------
    C:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : 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::all
    ocator<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:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : 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 information
    c:\program files\microsoft visual studio\vc98\include\iterator(176) : error C2679: binary '>>' : no operator defined which

    takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

    (
    or there is no acceptable conversion)
    c:\program files\microsoft visual studio\vc98\include\iterator(176) : while compiling class-template member function

    'void __thiscall std::istream_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
    >,char,struct std::char_traits<char> >::_Getval(void)'
    --------


    How to resolve the trouble?


    Thanks in advance,
    George

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    remove warnings

    George2,

    The warnings are harmless, nevertheless you can remove the warnings in VC6 with

    Code:
    #pragma warning(disable : 4786)
    placed at the top of your C++ or header file.

    I think the error is of some concern. You might have to write a global operator >> for some user-defined type in the class. I did not really study the example very closely and can not clearly indicate a solution.

    Chris.
    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    dude_1967 is right about the warnings. As far as the error is
    concerned, have you thought about "#include <string>" ?

  4. #4
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    Thanks, PaulWendt buddies!

    George

    Originally posted by PaulWendt
    dude_1967 is right about the warnings. As far as the error is
    concerned, have you thought about "#include <string>" ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured