Programming Wiki: C STL Vectors

Programming Wiki : CppVectorTips

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

C++ STL Vectors

Cpp


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
    }

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

Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.0762 seconds