Fedora Linux Support Community & Resources Center
  #1  
Old 5th March 2007, 02:44 PM
fc5pjs Offline
Registered User
 
Join Date: Apr 2006
Location: Singapore
Posts: 54
C++, STL Programming

Hi,
I am new to STL programming, need help on how to find an element especially from vector of user defind type objs.

myclass.h
--------------------------------
Class myclass {
private:
string md_name1, md_name2;
int md_usr_id;
public:
myclass();
~myclass();
};


vmain.cpp
------------

int main()
{
vector<myclass>::iterator lv_find_result;
vector<myclass> lv_vecMyclass_Obj;
//populate value, say (a1, a11, 1) (a2, a22, 2) (a3, a33, 3) for md_name1, name2, id respectively....

//now want to find a particular name say a55 using find algorithm
lv_find_result = find (lv_vecMyclass_Obj.begin(), lv_vecMyclass_Obj.end(), ??);

How should i fill 3rd arg in find algo such that it will find name a55?

return 0;
}

-FC5PJS

Last edited by fc5pjs; 5th March 2007 at 02:46 PM.
Reply With Quote
  #2  
Old 5th March 2007, 10:03 PM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,076
Define the "<" and "==" operators for your class to use the find() algorithm. The third argument is simply a myclass object to which the vector members are compared.

Last edited by markkuk; 5th March 2007 at 10:06 PM.
Reply With Quote
  #3  
Old 6th March 2007, 07:51 PM
tabish121 Offline
Registered User
 
Join Date: Nov 2005
Age: 38
Posts: 102
For C++ STL programming I find this book to be an invaluable reference.
http://www.amazon.com/C++-Standard-L.../dp/0201379260
Reply With Quote
  #4  
Old 7th March 2007, 02:26 AM
fc5pjs Offline
Registered User
 
Join Date: Apr 2006
Location: Singapore
Posts: 54
Smile

markkuk and tabish121 thanks for your help and info. Implemented "==" operator in my class.
Reply With Quote
Reply

Tags
programming, stl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
USB Programming? CrystalCowboy Using Fedora 1 29th October 2008 06:48 PM
3D programming alexgeek Programming & Packaging 1 1st July 2008 04:23 AM
Programming help please ejgutierrez Programming & Packaging 17 30th April 2008 06:24 PM
linux programming vs. windows programming unlovedwarrior Programming & Packaging 11 22nd October 2006 09:14 PM
C Programming jai Using Fedora 12 8th March 2006 02:23 AM


Current GMT-time: 08:38 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat