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 - 1) vector method and iterator (simple Example)       Share
2008-11-03 |  RatheeshTR  | Viewed: 1253  |    0


#include <algorithm>
#include <vector>
#include <iostream.h>
#include <assert.h>
        

class TwiceOver {

public:

    bool operator() ( 
int val1, int val2 )
         { 

return val1 == val2/2 ? true : false; 

}

};

        

int main()
{

   
int ia[] = { 1, 4, 4, 8 };
    vector< int, allocator > vec( ia, ia+4 );

                

    
int *piter;
    vector< int, allocator >::iterator iter;

                

   
//  piter  points  to  ia[1]
    piter = adjacent_find( ia, ia+4 );

    assert( *piter == ia[ 1 ] );

                

   
//  iter  points  to  vec[2]
    iter = adjacent_find( vec.begin(), vec.end(), TwiceOver() );

    assert( *iter == vec[ 2 ] );

                

   
//  reach  here:  everything  ok
cout << "ok: adjacent-find() succeeded!\n";

 }


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
performance testing
test design
unit, integration and system testing
testing techinical terms
software testing : test plan
tips to improve self-esteem
internet cache protocol
vnc viewer error server closed connection unexpectedly

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