社区
C语言
帖子详情
vector
的指针,怎样使用它的[ ]操作符?
jinux
2002-12-16 06:15:31
例如:
vector<int> *vx=new vector<int>(10);
...
cout<<vx[0]<<endl;
cout<<*vx[1]<<endl; //我想输出vector中的数值,不知那一句能实现?
...全文
155
6
打赏
收藏
vector<int>的指针,怎样使用它的[ ]操作符?
例如: vector *vx=new vector(10); ... cout<<vx[0]<<endl; cout<<*vx[1]<<endl; //我想输出vector中的数值,不知那一句能实现?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jinux
2002-12-16
打赏
举报
回复
谢谢,结贴送分
liu_feng_fly
2002-12-16
打赏
举报
回复
是的,通过指针调用成员函数operator[]
jinux
2002-12-16
打赏
举报
回复
谢谢二位!
to: liu_feng_fly(笑看风云 搏击苍穹 衔日月)
我觉得(*vx)[0]还能理解,可是上面的:vx->operator [](0)却不能理解,能简单说说吗?
就是说使用vector的operator[]成员函数,以0为参数?
liu_feng_fly
2002-12-16
打赏
举报
回复
vx->operator [](0)
或者
(*vx)[0]
ginger
2002-12-16
打赏
举报
回复
错了。
If the return value of operator[] is assigned to a const_reference, the vector object cannot be modified. If the return value of operator[] is assigned to a reference, the vector object can be modified.
ginger
2002-12-16
打赏
举报
回复
是这句:cout<<vx[0]<<endl;
priority_queue<
int
,
vector
<
int
>,greater<
int
>>优先队列 按照由小到大顺序
C++优先队列的基本
使用
方法 #include #include #include using namespace std; struct node { friend bool operator { return n1.priority "为从小打到排列 }
int
priority;
int
value;...
priority_queue<
int
,
vector
<
int
>,greater<
int
>>优先队列,按照从小到大
原网址: 优先队列 C++优先队列的基本
使用
...priority_queue
int
> qi; 通过 故示例1中输出结果为:9 6 5 3 2 第二种方法: 在示例1中,如果我们要把元素从小到大输出怎么办呢? 这时我们可以传入一
【priority_queue<
int
,
vector
<
int
>,greater<
int
>>优先队列 按照由小到大顺序】
C++优先队列的基本
使用
方法 #includeincludeincludeusing namespace std; struct node { friend bool operator< (node n1, node n2) { return n1.priority < n2.priority;//”<”为从大到小排列,”>”为...
vector
用法详解
<br />1.
vector
的数据的存入和输出:<br /><br />#include<stdio.h><br />#include<
vector
><br />#include <iostream><br /><br />using namespace std;<br /><br />void main()<br /><br />{<br /><br />
int
i =...
避免
使用
std::
vector
<bool>
无意间看到代码里
使用
std::
vector
<bool>, 感觉有点怪异,没有
使用
过。于是查了一下,正好effective stl 不建议
使用
std::
vector
<bool>: 做为一个STL容器,
vector
<bool>确实只有两个问题。第一,...
C语言
70,032
社区成员
243,245
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章