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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:28:45+00:00 2026-05-25T16:28:45+00:00

I have loads of c++ classes that reads data from a file stream. The

  • 0

I have loads of c++ classes that reads data from a file stream. The functions looks like this.

bool LoadFromFile(class ifstream &file);

I’m creating a new function to read from memory instead of a file. So I googled around and a istringstream seems to do the trick without any modifications to the code.

bool LoadFromData(class istringstream &file);

Now my question is. I need to construct this stream to read from a char array. The string is not null-terminated, it’s pure binary data and I got a integer with the size. I tried assigning it to a string and creating a stream from a string, however the string terminates after a null character.. and the data is copied.

int size;
char *data;
string s = *data;

How do I create a string from a char array pointer without copying the data + specifying the size of the pointer data? Do you know any other solution than a stringstream?

  • 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-05-25T16:28:46+00:00Added an answer on May 25, 2026 at 4:28 pm

    Write an own basic_streambuf class! More details.. (This way you could work on the current memory.)

    To create string from pointer and size: string str(data,data+size); (it will copy the data).

    On more thing: you should rewrite your functions to based on istream:

    bool LoadFromStream(istream &is);
    

    In this way you could do the followings, because both istringstream and ifstream based on istream (later this function could also supports tcp streams…):

    ifstream file;
    istringstream sstream;
    
    LoadFromStream(file);
    LoadFromStream(sstream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program that loads thirdparty class files (classes I did not
I have this class that have a function to load other classes and create
I have a framework that loads a lot of child collections from a non-database
Currently i have an application that reads and writes several properties from one or
I have this small app that loads plugin type components that other users can
I have code that loads a bunch of images into hidden img elements and
I have a swf with loads text into a Sprite that resizes based on
We have an engine that loads dlls dynamically (whatever is located in a certain
I have an application that loads external SWF files and plays them inside a
You'll have to forgive me on this one. I understand that the issue 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.