Iterator Class Object and common pointer

Source: Internet
Author: User
# Include <iostream>
# Include <vector>
# Include <iterator>
# Include <string>
Using namespace STD;
Int main ()
{
Vector <string> VEC;
String str1 ("AAA"), str2 ("BBB"), * P;
Vector <string >:: iterator it;
VEC. insert (VEC. Begin (), str1 );
VEC. insert (VEC. End (), str2 );
For (IT = Vec. Begin (); It <Vec. End (); It ++)
Cout <* It <Endl;
Cout <Endl;
For (P = Vec. Begin (); P <Vec. End (); P ++)
Cout <* P <Endl;
Return 0;
}

 

The iterator is a generalized pointer, And the pointer meets all the requirements of the iterator. The iterator is the interface of STL algorithm, and the pointer is the iterator. Therefore, STL algorithm can use pointers to operate non-STL containers based on pointers.
Iterator is a class and P is a pointer. Do not confuse the class with the pointer.

As for the above example, some ides can be compiled (VC ++ 6), and some cannot (VC ++. net2003), can only be said to be the reason for implementing the C ++ standard support!

Thank you for your advice! Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.