For (vector <student-Info>: const-iterator iter = students. Begin (); iter! = Student. End (); ITER ++)
{
Cout <(* ITER). Name <Endl;
}
Each container has an associated iterator.
Container-type: const-iterator read-only
Iterator
Vector: Fast random access, similar to Arrays
List: Suitable for fast insertion and deletion, similar to linked list
List <student> extract_fails (list <student> & students)
{
List <student> fail;
List <student >:: iterator iter = students. Begin ();
While (ITER! = Students. End ())
{
If (fgrade (* ITER ))
{
Fail. push_back (* ITER );
Iter = students. Erase (ITER );
}
Else
++ ITER;
}
Return fail;
}
List cannot be sorted by sort with sortAlgorithmThe usage is as follows:
List <student> students;
Students. Sort (compare );
Copy Function
Copy (buttom. Begin (), bottom. End (), back. inserter (RET ));
Find a link on the page
Vector <string> find_urls (const string & S)
{
Vector <string> ret;
Typedef string: const-iterator ITER;
Iter B = S. Begin (), E = S. End ();
While (B! = E ){
B = url_beg (B, E); // find a letters
If (B! = E ){
ITER after = URL. End (B. e); // obtain the corresponding URL
Ret. push_back (string (B. After); // remember the URL
B = after;
}
}
Return ret;
}
Accumulate (V. Begin (), V. End (), 0.0); // The accumulate function, which belongs to the <numeric> library.
Understanding the use of algorithms, iterators, and iterators is the primary focus: algorithms act only on containers in the container, not the container itself.
To be continued ......