Thread: set?

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002


    what is wrong with the following?

    #include <algorithm>
    #include <iostream>
    #include <list>
    #include <set>
    #include <string>
    using namespace std;
    int main()
    	typedef set<string> WordSet;
    	typedef WordSet::iterator WordIter;
    	typedef list<WordIter> Index;
    	WordSet words;
    	Index input_order;
    	for (string new_word; cin >> new_word, new_word != "Quit";)
    		pair<WordIter, bool> &trace = words.insert(new_word);
    		if (trace.second)
    	copy(input_order.begin(), input_order.end(),
    		ostream_iterator<string>(cout, "\n"));
    	copy(words.begin(), words.end(),
    		ostream_iterator<string>(cout, "\n"));
    	return 0;
    when I try to compile I get an error at line 18...
    Illegal Implicit conversion

    why? I dont get it..

    Im using code warior 7.0 on mac os X..


  2. #2
    Registered User
    Join Date
    Mar 2002
    with all those unnecessary typedefs you must be looking forward to a career in Windows@ programming. 8-)

    If I counted right line 18 is this:

    pair<WordIter, bool> &trace = words.insert(new_word);

    In the future you're likely to get better quality and more abundant answers if you actually flag/highlight the offending line for anyone willing to look at the problem.

    The potential problem I have with this line is that I believe the insert method for STL sets returns void. Therefore trying to assign type void to a reference to a pair is an implicit conversion.

    Here's a slightly different function to accomplish what I think you were trying to do, words will be in "ascending" order from smallest string to largest input_order will maintain the chronological sequence of the string as they are inserted into the set, irrespective of the size of of the string.

    for (string new_word; cin >> new_word, new_word != "Quit"
    if(count(new_word) == 0)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  2. The new FAQ
    By Hammer in forum A Brief History of
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Set default directory with GetTempDir?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2003, 11:36 PM