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 8884023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:57:46+00:00 2026-06-14T20:57:46+00:00

In C/C++, strings are NULL terminated. Could I use stringstream as a memory stream

  • 0

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.

  • 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-14T20:57:48+00:00Added an answer on June 14, 2026 at 8:57 pm

    When storing character sequences in a std::string you can have included null characters. Correspondingly, a std::stringstream can 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 a std::string the 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:

    struct membuf
        : std::streambuf 
    {
            membuf(char* base, std::size_t size) {
            this->setp(base, base + size);
            this->setg(base, base, base + size);
        }
        std::size_t written() const { return this->pptr() - this->pbase(); }
        std::size_t read() const    { return this->gptr() - this->eback(); }
    };
    
    int main() {
        // obtain a buffer starting at base with size size
        membuf       sbuf(base, size);
        std::ostream out(&sbuf);
        out.write("1\08\09\0", 6); // write three digits and three null chars
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: A better way to compare Strings which could be null I have
I have a C++ DLL and some functions return Unicode null-terminated strings: void SomeFunc(wchar_t*
I have an array that is a NULL -terminated array of NULL -terminated strings
While I could use strings, I would like to understand why this small example
When soritng an array made of a mix of strings, null values and zeros,
I want to initialize arbitrary large strings. It is null terminated string of characters,
I've discovered that std::string s are very slow compared to old-fashioned null-terminated strings, so
Question It seems that PyWin32 is comfortable with giving null-terminated unicode strings as return
How to parse in c++ list of null-terminated Unicode strings where the list is
I am reading strings from a binary file. Each string is null-terminated. Encoding is

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.