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.