Errors with insert_iterator with a vector string handler

This is a discussion on Errors with insert_iterator with a vector string handler within the C++ Programming forums, part of the General Programming Boards category; Here are my errors: Code: /usr/include/c++/3.3.2/bits/stl_algo.h: In function `_OutputIter std::transform(_InputIter, _InputIter, _OutputIter, _UnaryOperation) [with _InputIter = __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > ...

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    Errors with insert_iterator with a vector string handler

    Here are my errors:
    Code:
    /usr/include/c++/3.3.2/bits/stl_algo.h: In function `_OutputIter std::transform(_InputIter, _InputIter, _OutputIter, _UnaryOperation) [with _InputIter = __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > >, _OutputIter = std::insert_iterator<std::set<std::string, std::less<std::string>, std::allocator<std::string> > >, _UnaryOperation = std::string&(String_Sentence::*)(std::string&)]':
    main.cpp:62:   instantiated from here
    /usr/include/c++/3.3.2/bits/stl_algo.h:746: error: must use .* or ->* to call pointer-to-member function in `__unary_op (...)'
    main.cpp: In member function `void String_Sentence::Sort()':
    main.cpp:62: error: argument of type `std::string&(String_Sentence::)(std::string&)' does not match `std::string&(String_Sentence::*)(std::string&)'
    main.cpp:98:2: warning: no newline at end of file
    (sorry for the misused code tags, icouldnt find another way to remove the smiley faces through tags)
    and here is my code:

    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    #include <set>
    #include <map>
    #include <iterator>
    #include <algorithm>
    #include <cctype>
    using namespace std;
    
    void Display_String(string &s)
    {
    	cout << s << ' ';
    }
    char toLower(char ch) { return tolower(ch); }
    
    class String_Sentence
    {
    public:
    	vector<string> words;
    	set<string> wordset;
    	map<string, int> wordmap;
    	string input;
    	void Get_Input(string term);
    	int Find_Word(string s);
    	int Count_Words();
    	void Sort();
    	void Display();
    	void Display_Sorted();
    	void Display_Frequency();
    	string & LCase();
    	string & ToLower(string & s);
    };
    
    void String_Sentence::Get_Input(string term)
    {
    	while (cin >> input && input != term)
    	{
    		words.push_back(input);
    	}
    }
    
    int String_Sentence::Find_Word(string s)
    {
    	int tmp = input.find(s);
    	if (tmp == string::npos)
    	{
    		tmp = -1;
    	}
    	return tmp;
    }
    /*
    int String_Sentence::Count_Words()
    {
    	 int i = 0;
    	 for_each(words.begin(), words.end(), i++);
    	 return i;
    }
    */
    void String_Sentence::Sort()
    {
    	transform(words.begin(), words.end(), insert_iterator<set<string> > (wordset, wordset.begin()), ToLower);
    }
    
    void String_Sentence::Display()
    {
    	for_each(words.begin(), words.end(), Display_String);
    }
    /*
    void String_Sentence::Display_Sorted()
    {
    	for_each(wordset.begin(), wordset.end(), Display_String);
    }
    
    void Display_Frequency()
    {
    	set<string>::iterator si;
    	for (si = wordset.begin(); si != wordset.end(), si++)
    	{
    		cout << *si << ": " << wordmap[*si] << endl;
    	}
    } 
    */
    string & String_Sentence::ToLower(string & s)
    {
    	transform(s.begin(), s.end(), s.begin(), toLower);
    	return s;
    }
    
    int main()
    {
    	String_Sentence s1;
    	cout << "Enter a sentence, enter quit to quit:\n";
    	s1.Get_Input("quit");
    	cout << "\nYou entered:\n";
    	s1.Display();
    	cout << endl;
    }
    I cannot find anything that helps me out on this. Any ideas?

    The code commented out is code with others errors on it. If you want, uncomment and attempt the compile and help me out with those errors. They're pretty much the same thing though.

    Thanks in advanced!

    -Blizz

    And okay, so this is transform, not insert_iterator, sorry 'bout that.
    Last edited by Blizzarddog; 05-29-2005 at 09:15 PM.
    This war, like the next war, is a war to end war.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    >> for_each(words.begin(), words.end(), i++);
    Replace all that with a simple call to words.size(). Otherwise you'll have to provid a real functor for the 3rd parameter.

    >>transform(words.begin(), words.end(), insert_iterator<set<string> > (wordset, wordset.begin()), ToLower);
    ToLower() needs to be a static member function to be used as a normal functor.
    More details: for_each: callback function

    gg

  3. #3
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    I have everything working now except for the word frequencies. it says 0 for every word. the wrods.size() worked fine, and I fixed it all by making ToLower a gloabal function, that link just got me really confused
    Thanks though!
    This war, like the next war, is a war to end war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 09:00 AM
  3. Errors with simple window handler
    By Chapmad in forum Windows Programming
    Replies: 11
    Last Post: 08-30-2004, 02:44 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21