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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:43:25+00:00 2026-05-27T21:43:25+00:00

I asked this question before but with less information than I have now. What

  • 0

I asked this question before but with less information than I have now.

What I essentially have is a data block of type char. That block contains filenames that I need to format and put into a vector. I initially thought the formation of this char block had three spaces between each filename. Now, I realize they are ‘/0’ null terminated characters. So the solution that was provided was fantastic for the example I gave when I thought that there were spaces rather than null chars.

Here is what the structure looks like. Also, I should point out I DO have the size of the character data block.

filename1.bmp/0/0/0brick.bmp/0/0/0toothpaste.gif/0/0/0

The way the best solution did it was this:

// The stringstream will do the dirty work and deal with the spaces.
   std::istringstream iss(s);

   // Your filenames will be put into this vector.
   std::vector<std::string> v;

   // Copy every filename to a vector.
   std::copy(std::istream_iterator<std::string>(iss),
    std::istream_iterator<std::string>(),
    std::back_inserter(v));

   // They are now in the vector, print them or do whatever you want with them!
   for(int i = 0; i < v.size(); ++i)
    std::cout << v[i] << "\n"; 

This works fantastic for my original question but not with the fact they are null chars instead of spaces. Is there any way to make the above example work. I tried replacing null chars in the array with spaces but that didn’t work.

Any ideas on the best way to format this char block into a vector of strings?

Thanks.

  • 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-27T21:43:26+00:00Added an answer on May 27, 2026 at 9:43 pm

    If you know your filenames don’t have embedded “\0” characters in them, then this should work. (untested)

    const char * buffer = "filename1.bmp/0/0/0brick.bmp/0/0/0toothpaste.gif/0/0/0";
    int size_of_buffer = 1234; //Or whatever the real value is
    
    const char * end_of_buffer = buffer + size_of_buffer;
    
    std::vector<std::string> v;
    
    while( buffer!=end_of_buffer)
    {
      v.push_back( std::string(buffer) );
      buffer = buffer+filename1.size()+3;
    }
    

    If they do have embedded null characters in the filename you’ll need to be a little cleverer.
    Something like this should work. (untested)

    char * start_of_filename = buffer;
    while( start_of_filename != end_of_buffer )
    {
    
      //Create a cursor at the current spot and move cursor until we hit three nulls
      char * scan_cursor = buffer;
      while( scan_cursor[0]!='\0' && scan_cursor[1]!='\0' && scan_cursor[2]!='\0' )
      {
         ++scan_cursor;
      }
    
      //From our start to the cursor is our word.
      v.push_back( std::string(start_of_filename,scan_cursor) );
    
      //Move on to the next word
      start_of_filename = scan_cursor+3;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked this before but I didn't get the question right so the
This question has been asked before ( link ) but I have slightly different
This question may have been asked before, but I had trouble finding an answer,
No doubt elements of this question have been asked before, but I'm having trouble
Various incarnations of this question have been asked here before, but I thought I'd
i have asked this question before but no answer was there. so asking again.
I know this question was asked before but I have the following simple code
i have asked this question before but the answer received was not applicable in
Guys I have asked this question before but did not receive a single comment
I asked this question before. But now I am wondering why the following 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.