C + + study, experiment Five

Source: Internet
Author: User

One

#include <iostream>#include<vector>#include<string>using namespacestd;//function DeclarationvoidOUTPUT1 (vector<string> &); voidOutput2 (vector<string> &); intmain () {vector<string>likes, dislikes;//create vector<string> objects likes and dislikes//add element values for vector<string> Array object likes (favorite book, Music, film, paintings,anime,sport,sportsman,etc)Likes.push_back ("Favorite Book"); Likes.push_back ("Music"); Likes.push_back ("film"); Likes.push_back ("Sport"); Likes.push_back ("Sportsman"); cout<<"-----I like these-----"<<Endl; //Call the child function output vector<string> Array object likes element valueoutput1 (likes); //add element values for vector<string> array object dislikesDislikes.push_back ("Paintings"); Dislikes.push_back ("Anime"); Dislikes.push_back ("etc"); cout<<"-----I Dislike these-----"<<Endl; //Call the child function output vector<string> Array object dislikes element valueOUTPUT1 (dislikes); //exchanging element values for vector<string> objects likes and dislikesLikes.swap (dislikes); cout<<"-----I likes these-----"<<Endl; //Call the child function output vector<string> Array object likes element valueOutput2 (likes); cout<<"-----I Dislikes these-----"<<Endl; //Call the child function output vector<string> Array object dislikes element valueOutput2 (dislikes); return 0;}//function Implementation//output The element value of the vector<string> array Object v with the following labelvoidOUTPUT1 (vector<string> &v) {inti;  for(i=0; I<v.size (); i++) cout<<v[i]<<Endl;}//function Implementation//output The element value of the vector<string> array Object v in an iteratorvoidOutput2 (vector<string> &v) {//using iterators to access elements in a vectorvector<string>:: Iterator i;  for(i= v.begin (); I<v.end (); + +i) cout<<*i<<Endl; }
Ex1

C + + study, experiment Five

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.