Learn how an input iterator is used to read the values of an object. It is read-only and is the simplest form of iterator.
- [Instructor] An input iterator is the simplest form of iterator. It may be used to read values of an object once and then increment. Here I have a working copy of input-interator.cpp from Chapter Three of the exercise files. An input iterator is the simplest and most limited form of iterator. It's capable of reading but not writing, incrementing but not decrementing, and once a value is read it cannot be read again. The iostream object uses an input iterator for cin.
And because of the unique nature of the cin object, again, all it does is read from a stream. The input iterator is defined separately. So here we declare it with the istream_iterator type and the type that it points to. And the default constructor, defaults to end of stream. So this is used for testing if you get to the end of the stream. And the standard in iterator is declared by passing cin as its parameter.
So we use the input iterator like this. We test for end of stream, and if we don't have end of stream, we read the value and increment. And for our second value, we're not going to increment, and we're just going to read two values from cin, from standard in, and their numeric values because we've declared our iterator as having a double type. And we'll just multiply the two values together. So when I build and run, I can enter two numeric values.
And, when I press Enter to submit, it grabs those two values and multiplies them together and it gives me the result. So this is what the input iterator does. Any additional functionality would make no sense for an input stream. It's very simple, and very limited, and it works well for its purpose.
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.