In C/C++, strings are NULL terminated.
Could I use stringstream as a memory stream like MemoryStream in C#?
Data of memory streams may have \0 values in the middle of data, but C++ strings are NULL terminated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
When storing character sequences in a
std::stringyou can have included null characters. Correspondingly, astd::stringstreamcan deal with embedded null characters as well. However, the various formatted operations on streams won’t pass through the null characters. Also, when using a built-in string to assign values to astd::stringthe null characters will matter, i.e., you’d need to use the various overloads taking the size of the character sequence as argument.What exactly are you trying to achieve? There may be an easier approach than traveling in string streams. For example, if you want to read the stream interface to interact with a memory buffer, a custom stream buffer is really easy to write and setup: