Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:55:56+00:00 2026-06-10T02:55:56+00:00

I guess somebody had to ask these questions, so please bear with me. Let’s

  • 0

I guess somebody had to ask these questions, so please bear with me.

Let’s consider the following beasts:

  • ostream
  • istream
  • iostream
  • streambuf
  • string – Following Benjamin’s observation, this one does not belong here.
  • stringbuf

and the following iterators:

  • ostream_iterator
  • ostreambuf_iterator
  • istream_iterator
  • istreambuf_iterator

Questions:

Why isn’t there any iostream_iterator, streambuf_iterator, string_iterator (std::string::iterator and std::string::const_iterator do exist) or stringbuf_iterator?

Why don’t the 4 iterators listed above have a const version like std::vector<T>::const_iterator?

How are we supposed to iterate over any of those beasts if they don’t provide the begin() and end() methods? What is the purpose of the above 4 iterators?

N00b question: Where can I find a good reference that details the logic behind these classes and, also, some decent examples on how to use them?

Hopefully, someone with experience will provide a good answer for the above questions.


PS: Real life situation:

void writeToStream(std::ostream &out);
int main ()
{
    std::ostringstream byteStream;
    writeToStream(byteStream);
    std::string byteString = byteStream.str();

    for (unsigned short i = 0; i < byteString.size(); ++i)
    {
        //do something with each byteString[i]
    }
    return 0;
}

My guess is that I could have used ostream and iterate over its elements by using an iterator just like for std::vector, instead of using ostringstream and the str() method to convert it to a string, but I couldn’t find any information regarding this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:55:57+00:00Added an answer on June 10, 2026 at 2:55 am

    Why isn’t there any:
    * iostream_iterator
    * streambuf_iterator

    Don’t know. Probably because the semantics would be hard to define when doing both input and output. What do you expect to happen when you go forward and then backwards in a stream with an iterator?

    • string_iterator
    • stringbuf_iterator?

    These are easily covered by the existing iterators:

    std::string                  line; // load line.
    std::stringstream            linestream(line);
    std::istream_iterator<int>   lineIterator(linestream);
    

    Why don’t the 4 iterators listed above have a const version like std::vector::const_iterator?

    Because when you iterate across a stream the state of the stream is changing.

    How are we supposed to iterate over any of those beasts if they don’t provide the begin() and end() methods? What is the purpose of the above 4 iterators?

    Because a stream is usually one direction. You don’t iterate from the beginning but rather iterate from the current position in the stream to the end. So you just declare an iterator specifying the stream. The iterator starts at the current position and moves towards the end. You can declare an end of stream iterator by just not spcifying the stream.

     std::istream_iterator<int>   loop(std::cin);
     for(;loop != std::istream_iterator<int>(); ++loop)
     {
         std::cout << *loop;
     }
    

    N00b question: Where can I find a good reference that details the logic behind these classes and, also, some decent examples on how to use them?

    Here is a good place.
    Do a search for “C++ istream_iterator” you will get a lot of hits.

    Hopefully, someone with experience will provide a good answer for the above questions.

    Hopefully.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I guess this is a classical question for somebody with MSC in CS.
Could somebody please provide an example where getters and setters are not required? I
Can somebody help me guess out this code..this is just a snippet and I
Could somebody please help me setup Emacs Tramp to do a double hop? I
Could somebody please help me understand the concept of 'impersonation'? The way I understand
please have a look at the following code: (I removed all doctypes etc for
Guess that I have a TextView that I want to update it in some
I guess that the difficult part is the source. Do you know any webpage
I guess getView() is called for each item of the list, but my question
I guess my general question which I googled to no luck: Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.