STL的vector<string>的初始化方式总结
2017-09-29 10:44
543 查看
(1)第一种,类似于数组的方式:
[cpp] view
plain copy
print?
std::vector<std::string> strArray(10);
strArray[0] = "hello";
strArray[1] = "world";
strArray[2] = "this";
strArray[3] = "find";
strArray[4] = "gank";
strArray[5] = "pink";
strArray[6 ]= "that";
strArray[7] = "when";
strArray[8] = "how";
strArray[9] = "cpp";
(2)push_back的方式:
[cpp] view
plain copy
print?
vector<string> strArray;
strArray.push_back("hello");
strArray.push_back("world");
strArray.push_back("this");
strArray.push_back("find");
strArray.push_back("gank");
strArray.push_back("pink");
strArray.push_back("that");
strArray.push_back("when");
strArray.push_back("how");
strArray.push_back("cpp");
(3)构造函数的方式:
[cpp] view
plain copy
print?
string str[]={"hello","world","this","find","gank","pink","that","when","how","cpp"};
vector<string> strArray(str, str+10);
[cpp] view
plain copy
print?
std::vector<std::string> strArray(10);
strArray[0] = "hello";
strArray[1] = "world";
strArray[2] = "this";
strArray[3] = "find";
strArray[4] = "gank";
strArray[5] = "pink";
strArray[6 ]= "that";
strArray[7] = "when";
strArray[8] = "how";
strArray[9] = "cpp";
(2)push_back的方式:
[cpp] view
plain copy
print?
vector<string> strArray;
strArray.push_back("hello");
strArray.push_back("world");
strArray.push_back("this");
strArray.push_back("find");
strArray.push_back("gank");
strArray.push_back("pink");
strArray.push_back("that");
strArray.push_back("when");
strArray.push_back("how");
strArray.push_back("cpp");
(3)构造函数的方式:
[cpp] view
plain copy
print?
string str[]={"hello","world","this","find","gank","pink","that","when","how","cpp"};
vector<string> strArray(str, str+10);
相关文章推荐
- STL的vector<string>的初始化方式总结
- STL的vector<string>的三种简单初始化方式
- STL的vector<string>的初始化方式总结
- C++11特性:列表初始化:VS2010中vector<string>的初始化方式
- STL vector<bool>总结
- vector<Mat>作为类成员变量,初始化问题
- vector<vector<int> >初始化
- JavaSE8基础 Vector<String> size与elementAt配合for循环遍历
- vector使用方法,初始化vector<int> ivec( iarray,iarray+count );
- &lt;Effective STL&gt;笔记--vector和string
- STL_vector<>
- 关于类 HashMap<K,V> 遍历方式及HashMap<String,String>和HashMap<Person,Person>
- 实战c++中的vector系列--vector<unique_ptr<>>初始化(全部权转移)
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数“应输入 2 个参数,却提供了 3 个)
- Map<String,String>集合的四种遍历方式 其中有一种针对大容量的数据集合
- STL<vector>用法汇总
- Java基础<异常机制>总结(异常体系、Exception特点、异常处理方式)
- vector<bool>STL中的陷阱
- 为什么一般用vector<string> 而非 vector<char*>
- STL:vector<bool> 和bitset