home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2866
Discussions: 188,381, Posts: 2,243,474, Members: 232,609
Old October 30th, 2002, 09:38 PM   Digg it!   #1 (permalink)
Member
 
Join Date: Apr 2002
Posts: 97
Send a message via AIM to BlackRain
Exclamation
Got Another Question

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???
__________________

Shiggidie Shiggidie Schwag

BlackRain is offline   Reply With Quote
Old October 30th, 2002, 11:00 PM     #2 (permalink)
Member
 
Join Date: Feb 2002
Posts: 161
unique() takes a pair of iterators, so you should be calling it like this:
unique(listing.begin(), listing.end());

Also, note that unique() doesn't actually remove items from the collection. Instead, it moves the duplicate items to the end, and returns an iterator to the end of the unique subarray. You'll probably want to use this iterator in your for loop's conditional check, instead of using listing.end().

Martee is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2886)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
hp compaq nc6000 problems (138)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Recent Discussions
Need help removing my front usb.. (2)
Genuine Broadband Connection my.. (14)
BATCH FILE WONT OPEN!!! HELP!!! (3)
New Build ( Finally ) (2)
2nd video card (0)
RCA 52Inch HDTV wont turn on (1)
Building a gaming computer advi.. (1)
Best digital camera for under 2.. (14)
Help with an Ati Radeon HD 4850.. (25)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 09:09 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28