STL:如何将新添加的项的序列号放入集合中 [英] STL: how to get the sequence number of a newly added item into a set

查看:69
本文介绍了STL:如何将新添加的项的序列号放入集合中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在套装< Tcontainer

上执行成功的insert()或find()之后,是否可以获得该套装中此商品的商品编号?

(即,其基于零的序列号(位置/位置/等级/索引)

在已排序的集合中)


其他信息:

insert()返回一对< Tand find()返回一个迭代器。

使用这两个对象中的任何一个都可以获得

序列号这些对象指向的项目?

在insert()或find()之后,容器不会被修改。

解决方案

在文章< g1 ********** @ aioe.org>中, bi ******* @ bilgekhanbilgekhan.net.tr

说...


做完之后一个成功的insert()或find()在一个集合< Tcontainer

是否可以获得该集合中该项目的项目编号?

( ie。从零开始的序列号(位置/位置/等级/索引)

在已分类的集合中)


其他信息:

insert()返回一对< Tand find()返回一个迭代器。

使用这两个对象中的任何一个都可以获得

的序列号这些对象指向的项目?



your_iterator = yourset.find(无论如何);

std :: distance(yourset.begin(),your_iterator);


-

后来,

杰瑞。


宇宙是它的一个虚构bilgekhan写道:


在成功完成insert()或find()后设置< Tcontainer

是否可以在集合中获取此项目的项目编号?

(即从零开始的序列号(位置/位置/等级/) ()



没有序列号对于一组成员。通过迭代器访问

集的各个成员。


附加信息:

insert()返回一对< ; Tand find()返回一个迭代器。

使用这两个对象中的任何一个是否可以获得这些对象指向的项目的

序列号?



否,因为没有像序列号这样的概念。它不存在
。集合是一个不透明的集合,具有某些属性。

集合包含一个集合集合。的项目。

定义了一些操作。就是这样。

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.9(GNU / Linux)


iEYEABECAAYFAkg5nFIACgkQx9p3GYHlUOJdOACffjSkVb + 8zH iUD + HIyucsSB9d

AVUAn20V5OkYlH + SNv0ook90UT02hj0h

= FY7F

----- END PGP签名-----


" bilgekhan" < bi ******* @ bilgekhanbilgekhan.net.trwrote:


在set< Tcontainer <上执行成功的insert()或find()之后br />
是否可以在集合中获取此项目的项目编号?


(即其从零开始的序列号(位置/位置/等级/)索引)

在排序的集合中)


附加信息:

insert()返回一对< Tand find()返回一个迭代器。

使用这两个对象中的任何一个都可以获得这些对象指向的项目的

序列号?

之后insert()或find()容器不会被修改。



set< int> :: iterator it = s.insert(x).first;

//或= s.find( x);


int seqNumb = distance(s.begin(),it);


After doing a succcessful insert() or find() on a set<Tcontainer
is it possible to get the item number of this item in the set?
(ie. its zero-based sequence number (position/location/rank/index)
within the sorted collection)

Additional info:
insert() returns a pair<Tand find() returns an iterator.
Using any of these two objects is it possible to get the
sequence number of the item these objects point to?
After the insert() or find() the container won''t be modified.

解决方案

In article <g1**********@aioe.org>, bi*******@bilgekhanbilgekhan.net.tr
says...

After doing a succcessful insert() or find() on a set<Tcontainer
is it possible to get the item number of this item in the set?
(ie. its zero-based sequence number (position/location/rank/index)
within the sorted collection)

Additional info:
insert() returns a pair<Tand find() returns an iterator.
Using any of these two objects is it possible to get the
sequence number of the item these objects point to?

your_iterator = yourset.find(whatever);
std::distance(yourset.begin(), your_iterator);

--
Later,
Jerry.

The universe is a figment of its own imagination.


bilgekhan writes:

After doing a succcessful insert() or find() on a set<Tcontainer
is it possible to get the item number of this item in the set?
(ie. its zero-based sequence number (position/location/rank/index)
within the sorted collection)

There are no "sequence numbers" for members of a set. Individual members of
sets are accessed via iterators.

Additional info:
insert() returns a pair<Tand find() returns an iterator.
Using any of these two objects is it possible to get the
sequence number of the item these objects point to?

No, because there is no such a concept as a "sequence number". It doesn''t
exist. A set is an opaque collection, with certain properties. The
collection contains a "set" of items. A number of operations are defined on
a set. That''s it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkg5nFIACgkQx9p3GYHlUOJdOACffjSkVb+8zH iUD+HIyucsSB9d
AVUAn20V5OkYlH+SNv0ook90UT02hj0h
=FY7F
-----END PGP SIGNATURE-----


"bilgekhan" <bi*******@bilgekhanbilgekhan.net.trwrote:

After doing a succcessful insert() or find() on a set<Tcontainer
is it possible to get the item number of this item in the set?

(ie. its zero-based sequence number (position/location/rank/index)
within the sorted collection)

Additional info:
insert() returns a pair<Tand find() returns an iterator.
Using any of these two objects is it possible to get the
sequence number of the item these objects point to?
After the insert() or find() the container won''t be modified.

set<int>::iterator it = s.insert( x ).first;
// or = s.find( x );

int seqNumb = distance( s.begin(), it );


这篇关于STL:如何将新添加的项的序列号放入集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆