Been trying to fix this for a day or two now (off and on of course - not 48 straight hours)
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
int main()
{
int wordcount = 0;
string word;
vector<string>listing; //defines a vector of strings
ifstream in ("words.txt");
if (!in)
{
cerr << "Cannot open words.txt" << endl;
return EXIT_SUCCESS;
}
while (in >> word)
{
wordcount++;
listing.push_back(word);
}
sort (listing.begin(), listing.end());
//eliminate duplicates by using unique
listing.unique();
for (vector<string>::iterator i = listing.begin(); i!= listing.end(); ++i)
cout << *i << endl;
in.close();
cout << "There were " << wordcount << " words" << endl;
return EXIT_SUCCESS;
}
When compiling.... this returns the error:
Compiling...
unique1.cpp
C:\unique1.cpp(34) : error C2039: 'unique' : is not a member of 'vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std
::allocator<char> > > >'
Error executing cl.exe.
unique1.exe - 1 error(s), 0 warning(s)
This all has to do with the use of the "unique" algorithm, except the way I have it typed in, I believe its a function..... What am I doing wrong???