[说明]
C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。

表12-3 vector模板类的部分方法

方法
含义
push_back(k) 向vector对象的尾部添加一个元素k
begin( ) 返回一个迭代器对象,该对象指向vector中的第一个元素
end( ) 返回一个迭代器对象,该对象指向vector中的最后一个元素
empty( ) 测试vector对象是否为空
erase(ptr) 删除vector中ptr指向的元素
[C++代码]
#include<iostream>
#include<vector>
using namespace (1) ;
typedef vector< (2) >INTZECTOR;
const int ARRAY_SIZE=6;
void ShowVector(INTVECTOR & theVector);
int main( )
INTVECTOR theVector;
//初始化theVector,将theVector的元素依次设置为0至5
for (int cEachItem=0; cEachItem<ARRAY_SIZE; cEachItem++)
theVector. push_back( (3) );
ShowVector(theVector); //依次输出theVector中的元素
theVector. erase(theVector. begin( )+3);
ShowVector(theVector);

void ShowVector(INTVECTOR & theVector)
if(theVector. empty( ))
cout<<"theVector is empty." <<endl; return;

INTVECTOR::iterator (4) ;
for(theIterator = theVector.begin( ); theIterator != theVector.end( );
theIterator++)
cout<< *theIterator;
if(theIterator ! =thevector. end( )-1)cout<<",";

cout<<endl;

该程序运行后的输出结果为:
0, 1 , 2, 3, 4, 5
(5)

题库:初级程序员 类型:填空题 时间:2017-07-03 11:59:14 免费下载:《填空集》Word试卷

[说明]
C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表12-3所示。

表12-3 vector模板类的部分方法

方法
含义
push_back(k) 向vector对象的尾部添加一个元素k
begin( ) 返回一个迭代器对象,该对象指向vector中的第一个元素
end( ) 返回一个迭代器对象,该对象指向vector中的最后一个元素
empty( ) 测试vector对象是否为空
erase(ptr) 删除vector中ptr指向的元素
[C++代码]
#include<iostream>
#include<vector>
using namespace (1) ;
typedef vector< (2) >INTZECTOR;
const int ARRAY_SIZE=6;
void ShowVector(INTVECTOR & theVector);
int main( )
INTVECTOR theVector;
//初始化theVector,将theVector的元素依次设置为0至5
for (int cEachItem=0; cEachItem<ARRAY_SIZE; cEachItem++)
theVector. push_back( (3) );
ShowVector(theVector); //依次输出theVector中的元素
theVector. erase(theVector. begin( )+3);
ShowVector(theVector);

void ShowVector(INTVECTOR & theVector)
if(theVector. empty( ))
cout<<"theVector is empty." <<endl; return;

INTVECTOR::iterator (4) ;
for(theIterator = theVector.begin( ); theIterator != theVector.end( );
theIterator++)
cout<< *theIterator;
if(theIterator ! =thevector. end( )-1)cout<<",";

cout<<endl;

该程序运行后的输出结果为:
0, 1 , 2, 3, 4, 5
(5)

[说明]  C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空问为std。vector模板类的部分方法说明如表

本题关键词:金属类压型板,C型行为模式,定型组合模板,定型组合钢模板,动态数据,模板面板,动态数值模式,模板,滑动式模板,移动式模板;

微信扫码获取答案解析
下载APP查看答案解析