标签:tor close png spl class ret for clu 实验
一,
#include <iostream> #include <vector> #include <string> using namespace std; // 函数声明 void output1(vector<string> &); void output2(vector<string> &); int main() { vector<string>likes, dislikes; // 创建vector<string>对象likes和dislikes // 为vector<string>数组对象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; // 调用子函数输出vector<string>数组对象likes的元素值 output1(likes); // 为vector<string>数组对象dislikes添加元素值 dislikes.push_back("paintings"); dislikes.push_back("anime"); dislikes.push_back("etc"); cout << "-----I dislike these-----" << endl; // 调用子函数输出vector<string>数组对象dislikes的元素值 output1(dislikes); // 交换vector<string>对象likes和dislikes的元素值 likes.swap(dislikes); cout << "-----I likes these-----" << endl; // 调用子函数输出vector<string>数组对象likes的元素值 output2(likes); cout << "-----I dislikes these-----" << endl; // 调用子函数输出vector<string>数组对象dislikes的元素值 output2(dislikes); return 0; } // 函数实现 // 以下标方式输出vector<string>数组对象v的元素值 void output1(vector<string> &v) { int i; for(i=0;i<v.size();i++) cout<<v[i]<<endl; } // 函数实现 // 以迭代器方式输出vector<string>数组对象v的元素值 void output2(vector<string> &v) { //使用迭代器访问vector中的元素 vector<string>::iterator i; for(i= v.begin() ; i<v.end() ; ++i) cout<<*i<<endl; }
标签:tor close png spl class ret for clu 实验
原文地址:https://www.cnblogs.com/769869657h/p/9078700.html