Welcome to pickSourcecode.com Login | Register    
pickZy.com
 Home  | search  | games  | General  | C  | C++  | Java  | Php  | Networking  | Visual Basic  | VC++  | Win32  | MFC  | JavaScript  | Jobs  | JavaScript  | Post jobs
Cpp - 8) list and set       Share
2008-11-03 |  RatheeshTR  | Viewed: 392  |    0

#include <algorithm>
//    list  and  set
#include <list>
#include <set>
#include <string>
#include <iostream.h>

//  provides  an  alternative  equality  operator
//  returns  true  if  string  is  contained  with  the
//  member  object  friend  set
class OurFriends {

public:

bool operator()( const string& str ) {

eturn ( friendset.count( str ));

}


static 
void
FriendSet( const string *fs, 
int count ) {
copy( fs, fs+count,

inserter( friendset, friendset.end() ));

}


private:

static set< string, less<string>, allocator > friendset;

};


set< string, less<string>, allocator > OurFriends::friendset;


int main()
{

string Pooh_friends[] = { "Piglet", "Tigger", "Eyeore"  };

string more_friends[] = { "Quasimodo", "Chip", "Piglet" };

list<string,allocator> lf( more_friends, more_friends+3 );


//  populate  a  list  of  pooh  friends
OurFriends::FriendSet( Pooh_friends, 3 );


list<string,allocator>::iterator our_mutual_friend;

our_mutual_friend =

find_
if( lf.begin(), lf.end(), OurFriends());

//  generates:
//      Ah,  imagine  our  friend  Piglet  is  also  a  friend  of  Pooh.
if ( our_mutual_friend != lf.end() )
cout << "Ah, imagine our friend "

<< *our_mutual_friend

<< " is also a friend of Pooh.\n";


return 0;

}


Comments:





Submit comment's

Type:

User Comment's:

Submitted By:
Prof: Software
Tech: C ,Cpp
Send Mail: malathi.v



Related topics
Stack Implementation
cpp stack example

General Topics
recursively delete subdirectories
superb sentences by 7 superb persons
ultimate love letter…
i am sharing my work strategy
to return the key board
freelance writers
best practices of functional test automation
automate functional testing process

Web site contents © Copyright 2007, All rights reserved.
Help | Terms and Conditions | Privacy Policy | About Us