Programming Wiki: C STL Vectors

Programming Wiki : CppVectorTips

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

C++ 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

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

There are no comments on this page. [Add comment]

Powered by Wikka Wakka Wiki
Page was generated in 0.1248 seconds