C ++ primer Chinese Version 4th exercise 9.13

Source: Internet
Author: User

/* Here I will write down some of my answers and comments for the exercises in C ++ primer 4th (Note: I didn't buy an answer book, so it is not guaranteed that it is correct. What do you think is wrong, I hope you can tell me) the requirements for source code running are the same as those in the book. The pre-compilation and using lines are omitted. If you still don't know what to say, you can ask me, but I am also a beginner and may not know, I know that I am a beginner when I am still studying C ++ Prime. You are welcome to repost it, but please keep the author's name "jiutian Yuling ". */

Vector <int >:: iterator findint (vector <int >:: iterator, vector <int >:: iterator, INT );
Int main ()
{
Vector <int> ivec;
For (INT I = 0; I! = 10; ++ I)
{
Ivec. push_back (I );
}
Vector <int>: iterator iiterator = ivec. Begin (), iterb = ivec. End ();
Vector <int>: iterator iterc = findint (iiter, iterb, 3); // you can try different calls by yourself
Cout <* iterc;
Return 0;
}

Vector <int >:: iterator findint (vector <int >:: iterator itbegin, vector <int >:: iterator itend,
Int aint) // This is the program
{
For (; itbegin! = Itend; ++ itbegin)
{
If (* itbegin = aint)
{
Return itbegin;
}
}
Cout <"Data couldn't be found." <Endl;
Return -- itend; // note that itend points to the next element of the last element and cannot be called *.
}

 

// Note: In 9.15, you only need to convert all the vectors into a list.

 

Related Article

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.