C ++ study Note 1

Source: Internet
Author: User

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 ......

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.