Programming Wiki: C STL Vectors

Programming Wiki : CppVectorTips

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2006-04-28 01:00:33 by ScottRippee [reorganized header]

Additions:

C++ STL Vectors

Cpp



Deletions:

Cpp

Cpp STL Vectors





Edited on 2006-04-01 01:23:26 by ScottRippee

No differences.


Oldest known version of this page was edited on 2006-04-01 01:23:11 by ScottRippee []
Page view:

Cpp


Cpp STL Vectors


Using the vector find method

    vector<string>::iterator viter;
    vector<string>::iterator start = myVec.begin();
    vector<string>::iterator end = myVec.end();

    // Search our vector to see if item has already been inserted
    viter = find( start, end, myStringToSearchFor );
    if( viter == end )
    {
        // Device not found lets insert
    myVec.push_back(myStringToSearchFor);
    }


I tried doing the above without setting an iterator to the start and end for find but it never found a match. For example find (myVec.begin(), myVec.end(), SearchString) would never be able to find the search string.


Iterating through a stl vector

    vector<string>::const_iterator viter;
    for( viter=myVec.begin(); viter != myVec.end(); viter++ )
    {
          //do stuff
    }
Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.0298 seconds