Vector容器的使用
来源:互联网 发布:九鼎投资 知乎 编辑:程序博客网 时间:2024/05/23 10:17
C++库中的contrainer类:标准容器类
最基本的标准容器Vector类
如vector<string>
,规定该vector对象只装string类型的对象,如果试图加入其它类型,会报错
//Vector示例#include <iostream>#include <vector>#include <fstream>#include <string>using namespace std;int main(void){ vector<string> v; ifstream in("Copy1.txt"); string s; //按行读取文件,每一行存入到Vector容器的元素中 getline(in,s) cout<<"按行读"<<std::endl; while(getline(in,s)){ v.push_back(s); } for(int i=0;i<v.size();i++){ cout<<i<<":"<<v[i]<<std::endl; } //以空白来分隔单词读取 in>>s cout<<"按空格读"<<std::endl; while(in>>s){ v.push_back(s); } for(int j=0;j<v.size();j++){ cout<<j<<":"<<v[j]<<std::endl; } return 0;}
0 0
- 容器Vector的使用
- 容器vector的使用
- Vector容器的使用
- vector容器的使用
- vector容器类的使用
- c++ vector容器的使用
- vector容器类的使用[c++ stl]
- C++向量容器vector的使用
- 使用STL的vector容器类
- C++中的容器vector的使用
- 关于 Vector容器的使用实例
- vector容器中iterator的使用
- Cocos2dx中类库中Vector<T>容器的使用
- C++容器-2顺序容器vector、list、deque的使用
- vector容器使用例子
- vector容器使用总结
- vector容器使用
- Vector容器使用总结
- poj_2492 A Bug's Life(并查集)
- shell脚本
- Aspose.Cells如何设置单元格数字和日期的显示格式
- extern用法总结
- 关于错误Failure [INSTALL_FAILED_ALREADY_EXISTS]的解决办法
- Vector容器的使用
- 高通平台上的AMSS(Modem端) windows环境搭建
- NSCalendar api
- maven ArchetypeDescriptor
- String、StringBuffer与StringBuilder之间区别
- mvc注解使用 @Repository @Required
- tomcat7性能调优
- 2017Android通用流行框架大全
- Apache Hadoop入门