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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:49:00+00:00 2026-06-06T16:49:00+00:00

i would like to process an undefinitely long string in C++ by chunks of

  • 0

i would like to process an undefinitely long string in C++ by chunks of a given fixed length (e.g. 15 chars).

The string is an attribute of the class in charge of processing it (let’s call the class “Person” and the attribute “_description”), and external code must call a method to process each chunk sequentially, e.g. Person::processDescription(). Another method allows to see if there is one more chunk to process, e.g. Person::isThereMoreDescriptionToBeProcessed().

In order to avoid dealing with indexes and possible side effects (errors with +1/-1, init..), someone suggested me to store an array of range_iterators (boost) and iterate over them for processing, but I don’t know the range_iterator concept and Boost docs did not help too much here.

I guess I will store 2 items (e.g. _currentItem and _endItem) as attributes of Person and do a check like

_currentItem == _endItem

in isThereMoreDescriptionToBeProcessed() and I guess I will do something like

_currentItem++

at the end of processDescription(), but I can’t understand how I can populate the array of range iterator at the init of the _description property for this purpose and how can i get the string to be processed in processDescription().

Thanks for throwing some lights on this.

  • 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-06T16:49:00+00:00Added an answer on June 6, 2026 at 4:49 pm

    Given two iterators that you want to create a range out of, you would just construct a boost::iterator_range and pass the two iterators as constructor arguments.

    The below code splits str into three character segments and pushes each segment into ranges.

    std::vector<boost::iterator_range<std::string::iterator>> ranges;
    std::string str = "abcdefghijk";
    
    auto it = str.begin();
    auto lastIt = it;
    while (it != str.end())
    {
        lastIt = it;
        if (std::distance(it, str.end()) < 3)
            it = str.end();
        else
            std::advance(it, 3);
    
        ranges.push_back(
            boost::iterator_range<std::string::iterator>(lastIt, it)
        );
    }
    
    for (auto segment = ranges.begin(); segment != ranges.end(); ++segment)
        std::cout << std::string(segment->begin(), segment->end()) << std::endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a very large string. I would like to process parts of the string
i would like to process infrared imaging in Matlab. Any kind of processing or
I would like to process a frame element in my source xml file using
I would like to run a process from Python (2.4/2.5/2.6) using Popen , and
I would like to know the process and service providers who will enable me
I would like to create a child process in node, and block in a
I would like to make log in process more safely. And to achieve it
I would like seek some guidance in writing a process profiler which runs in
I would like to have a manager process sharing graphs via shared memory, read-only
I have a huge graph that I would like to process using many machines.

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.