标签:pre algorithm vector names ica string ++ pac using
1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <algorithm> 5 using namespace std; 6 7 int main() 8 { 9 string str[] = {"Alex", "John", "Robert"}; 10 //创建一个空vector容器 11 vector<int> v1; 12 //创建一个有10个空元素的vector容器 13 vector<int> v2(10); 14 //创建一个有10个元素的vector容器,并为每个元素赋值为0 15 vector<int> v3(10,0); 16 //根据字符串数组创建vector容器 17 vector<string> v4(str,str + 3); 18 19 //创建迭代器 20 vector<string>::iterator sIt = v4.begin(); 21 while(sIt != v4.end()){ 22 cout<< *sIt ++ << " "; 23 } 24 cout<<endl; 25 26 //拷贝构造 27 vector<string> v5(v4); 28 for(int i = 0;i < 3;i ++){ 29 cout<< v5[i] << " "; 30 } 31 cout<<endl; 32 33 return 0; 34 }
标签:pre algorithm vector names ica string ++ pac using
原文地址:http://www.cnblogs.com/lca1826/p/6349886.html