初级程序员-填空集_10(精选试题)

上传人:h**** 文档编号:175427035 上传时间:2021-03-22 格式:DOC 页数:10 大小:25.50KB
返回 下载 相关 举报
初级程序员-填空集_10(精选试题)_第1页
第1页 / 共10页
初级程序员-填空集_10(精选试题)_第2页
第2页 / 共10页
初级程序员-填空集_10(精选试题)_第3页
第3页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《初级程序员-填空集_10(精选试题)》由会员分享,可在线阅读,更多相关《初级程序员-填空集_10(精选试题)(10页珍藏版)》请在金锄头文库上搜索。

1、精品文档_初级程序员-填空集1、说明C+标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。表12-3vector模板类的部分方法方法含义push_back(k)向vector对象的尾部添加一个元素kbegin()返回一个迭代器对象,该对象指向vector中的第一个元素end()返回一个迭代器对象,该对象指向vector中的最后一个元素empty()测试vector对象是否为空erase(ptr)删除vector中ptr指向的元素C+代码#includeiostream#includevec

2、torusingnamespace(1);typedefvector(2)INTZECTOR;constintARRAY_SIZE=6;voidShowVector(INTVECTOR&theVector);intmain()INTVECTORtheVector;/初始化theVector,将theVector的元素依次设置为0至5for(intcEachItem=0;cEachItemARRAY_SIZE;cEachItem+)theVector.push_back(3);ShowVector(theVector);/依次输出theVector中的元素theVector.erase(theV

3、ector.begin()+3);ShowVector(theVector);voidShowVector(INTVECTOR&theVector)if(theVector.empty()cout”theVectorisempty.”endl;return;INTVECTOR:iterator(4);for(theIterator=theVector.begin();theIterator!=theVector.end();theIterator+)cout*theIterator;if(theIterator!=thevector.end()-1)cout”,”;coutendl;该程序运行

4、后的输出结果为:0,1,2,3,4,5(5)2、说明C+标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。表12-3vector模板类的部分方法方法含义push_back(k)向vector对象的尾部添加一个元素kbegin()返回一个迭代器对象,该对象指向vector中的第一个元素end()返回一个迭代器对象,该对象指向vector中的最后一个元素empty()测试vector对象是否为空erase(ptr)删除vector中ptr指向的元素C+代码#includeiostream#in

5、cludevectorusingnamespace(1);typedefvector(2)INTZECTOR;constintARRAY_SIZE=6;voidShowVector(INTVECTOR&theVector);intmain()INTVECTORtheVector;/初始化theVector,将theVector的元素依次设置为0至5for(intcEachItem=0;cEachItemARRAY_SIZE;cEachItem+)theVector.push_back(3);ShowVector(theVector);/依次输出theVector中的元素theVector.er

6、ase(theVector.begin()+3);ShowVector(theVector);voidShowVector(INTVECTOR&theVector)if(theVector.empty()cout”theVectorisempty.”endl;return;INTVECTOR:iterator(4);for(theIterator=theVector.begin();theIterator!=theVector.end();theIterator+)cout*theIterator;if(theIterator!=thevector.end()-1)cout”,”;couten

7、dl;该程序运行后的输出结果为:0,1,2,3,4,5(5)3、说明C+标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。表12-3vector模板类的部分方法方法含义push_back(k)向vector对象的尾部添加一个元素kbegin()返回一个迭代器对象,该对象指向vector中的第一个元素end()返回一个迭代器对象,该对象指向vector中的最后一个元素empty()测试vector对象是否为空erase(ptr)删除vector中ptr指向的元素C+代码#includeios

8、tream#includevectorusingnamespace(1);typedefvector(2)INTZECTOR;constintARRAY_SIZE=6;voidShowVector(INTVECTOR&theVector);intmain()INTVECTORtheVector;/初始化theVector,将theVector的元素依次设置为0至5for(intcEachItem=0;cEachItemARRAY_SIZE;cEachItem+)theVector.push_back(3);ShowVector(theVector);/依次输出theVector中的元素theV

9、ector.erase(theVector.begin()+3);ShowVector(theVector);voidShowVector(INTVECTOR&theVector)if(theVector.empty()cout”theVectorisempty.”endl;return;INTVECTOR:iterator(4);for(theIterator=theVector.begin();theIterator!=theVector.end();theIterator+)cout*theIterator;if(theIterator!=thevector.end()-1)cout”,

10、”;coutendl;该程序运行后的输出结果为:0,1,2,3,4,5(5)4、说明C+标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。表12-3vector模板类的部分方法方法含义push_back(k)向vector对象的尾部添加一个元素kbegin()返回一个迭代器对象,该对象指向vector中的第一个元素end()返回一个迭代器对象,该对象指向vector中的最后一个元素empty()测试vector对象是否为空erase(ptr)删除vector中ptr指向的元素C+代码#in

11、cludeiostream#includevectorusingnamespace(1);typedefvector(2)INTZECTOR;constintARRAY_SIZE=6;voidShowVector(INTVECTOR&theVector);intmain()INTVECTORtheVector;/初始化theVector,将theVector的元素依次设置为0至5for(intcEachItem=0;cEachItemARRAY_SIZE;cEachItem+)theVector.push_back(3);ShowVector(theVector);/依次输出theVector

12、中的元素theVector.erase(theVector.begin()+3);ShowVector(theVector);voidShowVector(INTVECTOR&theVector)if(theVector.empty()cout”theVectorisempty.”endl;return;INTVECTOR:iterator(4);for(theIterator=theVector.begin();theIterator!=theVector.end();theIterator+)cout*theIterator;if(theIterator!=thevector.end()-

13、1)cout”,”;coutendl;该程序运行后的输出结果为:0,1,2,3,4,5(5)5、说明C+标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。表12-3vector模板类的部分方法方法含义push_back(k)向vector对象的尾部添加一个元素kbegin()返回一个迭代器对象,该对象指向vector中的第一个元素end()返回一个迭代器对象,该对象指向vector中的最后一个元素empty()测试vector对象是否为空erase(ptr)删除vector中ptr指向的元

14、素C+代码#includeiostream#includevectorusingnamespace(1);typedefvector(2)INTZECTOR;constintARRAY_SIZE=6;voidShowVector(INTVECTOR&theVector);intmain()INTVECTORtheVector;/初始化theVector,将theVector的元素依次设置为0至5for(intcEachItem=0;cEachItemARRAY_SIZE;cEachItem+)theVector.push_back(3);ShowVector(theVector);/依次输出theVector中的元素theVecto

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 其它考试类文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号