STL的vector<string>的三种简单初始化方式
2015-10-20 16:46
405 查看
(1)第一种,类似于数组的方式:
[cpp] view
plaincopyprint?
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
plaincopyprint?
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
plaincopyprint?
string str[]={"hello","world","this","find","gank","pink","that","when","how","cpp"};
vector<string> strArray(str, str+10);
[cpp] view
plaincopyprint?
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
plaincopyprint?
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
plaincopyprint?
string str[]={"hello","world","this","find","gank","pink","that","when","how","cpp"};
vector<string> strArray(str, str+10);
相关文章推荐
- 使用.tpl自定义的模板放到IIS上被拦截解决方案
- CGPath使用
- 时间格式:yyyy-MM-dd HH:mm:ss,YYYY-MM-dd hh:mm:ss等,详细解释
- GLSL实现图像处理
- docker居然需要3.10以上的内核
- 2015.10.19信息系统项目管理师作业
- Struts2 + Spring + hibernate 框架搭成实例
- CentOS6.5安装Scala2.10.3
- 8.2.1.9 LEFT JOIN and RIGHT JOIN Optimization 左关联和又关联
- QSqlQuery QSqlQueryModel QSqlTableModel的区别
- 一篇文章了解什么是增长黑客
- iOS开发:cocoapods的使用
- linux中nodejs后台运行工具forever
- [转] socket异步编程--libevent的使用
- Struts2 + Spring + hibernate 框架搭成实例
- css3 动画效果
- XCode7的使用与iOS 9适配的小结
- 第10回 这Service是怎么个思想感情啊?
- WindowManagerService动画分析
- 用Python和Pygame写游戏