| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 943 人关注过本帖
标题:[求助]请教c++关于vector容器的用法
只看楼主 加入收藏
keloy
Rank: 2
等 级:论坛游民
帖 子:107
专家分:16
注 册:2007-9-27
收藏
 问题点数:0 回复次数:5 
[求助]请教c++关于vector容器的用法

在使用vector<>中我有一个小问题,比如vector<string>做string的数组,可以用pash_back()输入,我想知道,怎样把指针指到任何一个已经输入的string的头???

搜索更多相关主题的帖子: vector 容器 用法 string 
2007-10-21 16:09
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

reference front( );
const_reference front( ) const;
///////////////////////////////////
for example:
#include <vector>
#include <iostream>

int main( )
{
using namespace std;
vector <int> v1;

v1.push_back( 10 );
v1.push_back( 11 );
v1.push_back( 12 );

int& i = v1.front( );
const int& ii = v1.front( );

cout << "The first integer of v1 is "<< i << endl;
i++;
cout << "The second integer of v1 is "<< ii << endl;
}


output:
The first integer of v1 is 10
The second integer of v1 is 11


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-10-21 16:18
keloy
Rank: 2
等 级:论坛游民
帖 子:107
专家分:16
注 册:2007-9-27
收藏
得分:0 
谢谢了,还有个问题


const int& ii = v1.front( ); 这句是什么意思
2007-10-21 16:33
msshadow
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-5-30
收藏
得分:0 
是队头元素吧..
2007-10-21 20:08
msshadow
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-5-30
收藏
得分:0 

include <queue>
#include <iostream>
int main() {
using namespace std;
queue <int> q1;

q1.push( 10 );
q1.push( 20 );
q1.push( 30 );

queue <int>::size_type i;
i = q1.size( );
cout << "The queue length is " << i << "." << endl;

int& ii = q1.back( );
int& iii = q1.front( );

cout << "The integer at the back of queue q1 is " << ii
<< "." << endl;
cout << "The integer at the front of queue q1 is " << iii
<< "." << endl;
}

2007-10-21 20:13
评梅
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-10-18
收藏
得分:0 
学习
2007-10-25 21:58
快速回复:[求助]请教c++关于vector容器的用法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012387 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved