Halil Arslan
3 min readOct 21, 2017

What Are String Streams And Differences Between Ostringstream, Istringstream and Stringstream #2

source

Today, string streams are my topic to write for my writing camp. To be honest, I am not as organized as I assume about my writing camp because I integrate some other things to my life and recently, I have struggled to make everything on a right path. This is my survivor to get a good path to pursue lifelong learning. For now, it is enough to say about a review of my previous week. This will be my second English article to improve my writing skills. For the first one, I will share the link to read it for you. Today as I mentioned, my subject is string streams in C++. I am currently developing myself in C++ to get knowledge about object-oriented programming and embedded software. Yesterday, I was dealing with one problem which includes some work about string streams. Toward this problem, I have searched and read something on the web and from books. Firstly, string streams are used to manipulate strings. For example, it eases to convert a string to other data types like ints, doubles etc. Also, it enables us to convert data types to string. By using string streams, you can efficiently process your strings. The library to use string streams in C++ is ;

#include <sstream>

I have learned three members of it until now:

1.stringstream
2.ostringstream
3.istringstream

I have gone through about this content, and I realized that by using stringstream I do not need to use other 2 members for my simple purpose.So, it blows my mind and then I made brief research about it and my result is that;
Stringstream is used to deal with both input and output streams with operator ‘ << ‘ which is used for inserting and ‘ >> ‘ which is used for extracting data.
Ostringstream, as we understand from the name, it is appropriate for output and it only uses ‘ << ‘ operator to insert data. It is better to use to get clarity about what you want from your code.
Istringstream, is again same logic, it is used for input operations and ‘ >> ‘ operator is used to extracting data.

Therefore, I have read something about performance issues between them but not gone through on them to avoid more details for now. From my point of view for now, if I want to get clarity about my purpose and not confuse about operator using, using i and o streams is better to implement. Otherwise, for my simple studies, I can manage what I want to achieve by using stringstream only.

Thank you for reading my article and I will be waiting for your comment to improve my writing and also if you encounter any mistake about my content, please inform this newbie programmer to develop himself. To read my previous article :
https://medium.com/@arslanhalil33/writing-camp-of-electronics-engineering-student-1-f8ccc30b6dda

Halil Arslan

Future electronic engineer who is always curious, constant reader and idea creator. For more about me: https://www.linkedin.com/in/arslanhalil/