string streams

Mar 1, 2016 at 6:28am
Why would a programmer want to use string streams, specifically objects of istrstream and ostrstream classes, for handling input to and output of a program?
Mar 1, 2016 at 7:40am
Homework?

It's ok if it is, I'm just curious.
Mar 1, 2016 at 7:51am
To simplify formatting.

For example, there is a ragged table:
1 3 7
4 6
2 2 9 8

Each line has different number of values. Not known beforehand.

We can std::getline one line into std::string. Then read integers via istringstream. Repeat for each line.


Besides, not all I/O is with console or file. You are reading this post with a browser, don't you? The browser receives HTML string from network connection. Then it has to parse the "input". Not reading a file, not waiting for the user to type. Yet, a browser could open a local file. Therefore, the parsing code probably takes a generic istream and it is called with either ifstream or istringstream object.
Last edited on Mar 1, 2016 at 8:52am
Mar 1, 2016 at 8:36am
specifically objects of istrstream and ostrstream classes

Actually, you should specifically not use these classes as they have been deprecated in favour of std::istringsteam and std::ostringstream.

Given they were deprecated over a decade and a half ago, your question is a bit dated!

Andy
Last edited on Mar 1, 2016 at 8:37am
Topic archived. No new replies allowed.