473,616 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterators on Vector

Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)

What is the best reference to understand which(iterator) can be
declared on which(container ) and how ?

Thanks.

Aug 23 '05 #1
3 2913
codefixer at gmail.com wrote:
I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.
Why would you want to? std::vectors (and the other predefined standard
containers) already have their iterators defined for you:
std::vector:ite rator etc.
OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.
Correct (although the term is "random access iterator" rather than
"random iterator," and a std::vector is spelled with an uncapitalized
"v").
But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)
A random access iterator has all the functionality of an input iterator
and all the functionality of an output iterator. You could define your
own iterator ("codefixer_ite rator") for a vector that was just an input
iterator or just an output iterator, but that would be silly and a
waste of time when vector already has a random access iterator
predefined for you.
What is the best reference to understand which(iterator) can be
declared on which(container ) and how ?


Josuttis's The C++ Standard Library.

But you seem to be missing the point. The standard containers already
have their iterators predefined, so you don't declare them.
std::vector, std::deque, and std::string have random access iterators.
std::list, std::set, and std::map have bidirectional iterators.
iterators into streams are typically either input or output iterators.
You typically define new iterators for new containers or sequences you
define, not for those already defined.

Best regards,

Tom

Aug 23 '05 #2
co*******@gmail .com wrote:
Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)

What is the best reference to understand which(iterator) can be
declared on which(container ) and how ?


The different iterator categories (input, output, etc.) are only
concepts. If a particular iterator type (e.g. vector<int>::it erator)
supports a specific set of operations it is of a particular category
(random access in the case of vector<int>::it erator).

Stefan
Aug 24 '05 #3

co*******@gmail .com schreef:
Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.


Yes. In fact, with the exception of Input/Output Iterators, the
iterator categories are nested. A random iterator is also a member of
all other categorie (e.g. it is both an input and an output iterator)

Regards,
Michiel Salters

Aug 24 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2230
by: sci | last post by:
class A; void function(vector<A>* l) { .... } main(){ vector<A> aAList; function(&aAList);
0
1490
by: marco_segurini | last post by:
Hi, I am trying to solve this problem: I have a vector V1 that is not empty and a vector V2 that contains some iterator that point to V1 elements. Now I want to remove the V1 elements that V2 elements reference using erase/remove_if idiom. //////// #include <algorithm>
11
2893
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any circumstances in which the STL will move a vector, or invalidate iterators to elements in the vector, if you don't insert or remove elements? My actual problem seems to be as follows: I have class X, which contains an STL vector. The constructor...
13
20125
by: zaineb | last post by:
Hi, This is a follow-up of sort of this thread: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/de12af6539e0d645/662cab752779f1fa?lnk=st&q=c%2B%2B+vector+vs+map&rnum=1&hl=en#662cab752779f1fa I've been chewing on this problem for a while. When I came across the above thread, I figured that maybe other members have a better idea on how to approach this. I'm currently trying to decide between which one of maps or...
23
6525
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: vector<string> tokenize(string s){
2
2339
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
9
4609
by: Christian Chrismann | last post by:
Hi, I've a runtime problem with STL vectors. Here is the simplified version of the code: template <class Tclass A { ... private: vector<T*myvector; typename vector<T*>::itarator mIt;
8
2264
by: desktop | last post by:
In accelerated C++ on page 146 there is this example: template <class In, class Out> Out copy(In begin, In end, Out dest) { While (begin != end) *dest++ = *begin++; return dest; }
9
3805
by: barcaroller | last post by:
1. If I pass pointers (char*) as iterators to an STL algorithm and the return value is an iterator, can I convert that iterator to a pointer? If yes, how? 2. What is the internal representation of vector<string>? Will the vector contain the string objects or will it contain pointers/references to the string objects? The reason I ask is that it is not clear to me how the v.reserve() and &v operations would work for a vector<string>.
0
8145
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8592
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8448
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4060
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4140
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.