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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:47:38+00:00 2026-05-15T00:47:38+00:00

I have a char array which contains null characters at random locations. I tried

  • 0

I have a char array which contains null characters at random locations. I tried to create an iStringStream using this array (encodedData_arr) as below,

I use this iStringStream to insert binary data(imagedata of Iplimage) to a MySQL database blob field(using MySQL Connector/C++’s setBlob(istream *is) ) it only stores the characters upto the first null character.

Is there a way to create an iStringStream using a char array with null characters?

unsigned char *encodedData_arr = new unsigned char[data_vector_uchar->size()];
// Assign the data of vector<unsigned char> to the encodedData_arr
for (int i = 0; i < vec_size; ++i)
{
 cout<< data_vector_uchar->at(i)<< " : "<< encodedData_arr[i]<<endl;
}

// Here the content of the encodedData_arr is same as the data_vector_uchar
// So char array is initializing fine.
istream *is = new istringstream((char*)encodedData_arr, istringstream::in || istringstream::binary);

prepStmt_insertImage->setBlob(1, is);
// Here only part of the data is stored in the database blob field (Upto the first null character)
  • 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-15T00:47:39+00:00Added an answer on May 15, 2026 at 12:47 am

    There is nothing special about null characters in strings

    std::istringstream iss(std::string(data, N));
    setBlob(&iss);
    

    Of course if you do

    std::istringstream iss("haha a null: \0");
    

    It will interpret that as a C-style string converted to std::string, and thus will stop at the \0, not taking it as a real content byte. Telling std::string the size explicitly allows it to consume any null byte as real content data.

    If you want to read directly from a char array, you can use strstream

    std::istrstream iss(data, N);
    

    That will directly read from the data provided by data, up to N bytes. strstream is declared “deprecated” officially, but it’s still going to be in C++0x, so you can use it. Or you create your own streambuf, if you really need to read from a raw char* like that.

    struct myrawr : std::streambuf {
      myrawr(char const *s, size_t n) { 
        setg(const_cast<char*>(s), 
             const_cast<char*>(s), 
             const_cast<char*>(s + n));
      }
    };
    
    struct hasb { 
      hasb(char const *s, size_t n)
       :m(s, n)
      { }
      myrawr m;
    };
    
    // using base-from-member idiom
    struct myrawrs : private hasb, std::istream {
      myrawrs(char const *s, size_t n)
        :hasb(s, n), 
         std::istream(&static_cast<hasb*>(this)->m)
      { }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 435k
  • Answers 435k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try to enclose the first parameter [Microsoft.Web.Deployment]::DeploymentWellKnownProvider.AppHostConfig with a pair… May 15, 2026 at 3:37 pm
  • Editorial Team
    Editorial Team added an answer I have implemented this solution using nested datalist controls. May 15, 2026 at 3:37 pm
  • Editorial Team
    Editorial Team added an answer Да очень просто It is easy to do with UTF-8… May 15, 2026 at 3:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.