C++ Primer(第5版) 练习 3.21
练习 3.21 请使用迭代器重做3.3.3节(第94页)的第一个练习。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************> File Name: ex3.16.cpp> Author: > Mail: > Created Time: Wed 31 Jan 2024 11:25:21 AM CST************************************************************************/#include<iostream>
#include<vector>
#include<cctype>
using namespace std;int main(){vector<int> v1;vector<int> v2(10);vector<int> v3(10, 42);vector<int> v4{10};vector<int> v5{10, 42};vector<string> v6{10};vector<string> v7{10, "hi"};cout<<"v1 size: "<<v1.size()<<endl;cout<<"v1: ";for(auto it = v1.cbegin(); it != v1.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v2 size: "<<v2.size()<<endl;cout<<"v2: ";for(auto it = v2.cbegin(); it != v2.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v3 size: "<<v3.size()<<endl;cout<<"v3: ";for(auto it = v3.cbegin(); it != v3.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v4 size: "<<v4.size()<<endl;cout<<"v4: ";for(auto it = v4.cbegin(); it != v4.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v5 size: "<<v5.size()<<endl;cout<<"v5 :";for(auto it = v5.cbegin(); it != v5.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v6 size: "<<v6.size()<<endl;cout<<"v6: ";for(auto it = v6.cbegin(); it != v6.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;cout<<"v7 size: "<<v7.size()<<endl;cout<<"v7: ";for(auto it = v7.cbegin(); it != v7.cend(); ++it){cout<<*it<<" ";}cout<<endl<<endl;return 0;
}