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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:03+00:00 2026-05-26T15:12:03+00:00

Is it possible to somehow adapt a c-style string/buffer ( char* or wchar_t* )

  • 0

Is it possible to somehow adapt a c-style string/buffer (char* or wchar_t*) to work with the Boost String Algorithms Library?

That is, for example, it’s trimalgorithm has the following declaration:

template<typename SequenceT> 
void trim(SequenceT &, const std::locale & = std::locale());

and the implementation (look for trim_left_if) requires that the sequence type has a member function erase.

How could I use that with a raw character pointer / c string buffer?

char* pStr = getSomeCString(); // example, could also be something like wchar_t buf[256];
...
boost::trim(pStr); // HOW?

Ideally, the algorithms would work directly on the supplied buffer. (As far as possible. it obviously can’t work if an algorithm needs to allocate additional space in the "string".)


@Vitaly asks: why can’t you create a std::string from char buffer and then use it in algorithms?

The reason I have char* at all is that I’d like to use a few algorthims on our existing codebase. Refactoring all the char buffers to string would be more work than it’s worth, and when changing or adapting something it would be nice to just be able to apply a given algorithm to any c-style string that happens to live in the current code.

Using a string would mean to (a) copy char* to string, (b) apply algorithm to string and (c) copy string back into char buffer.

  • 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-26T15:12:03+00:00Added an answer on May 26, 2026 at 3:12 pm

    For the SequenceT-type operations, you probably have to use std::string. If you wanted to implement that by yourself, you’d have to fulfill many more requirements for creation, destruction, value semantics etc. You’d basically end up with your implementation of std::string.

    The RangeT-type operations might be, however, usable on char*s using the iterator_range from Boost.Range library. I didn’t try it, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it somehow possible on Swing to set a TitledBorder transparent so that a
I'm wondering if it's possible somehow to play a video that has sound (in
Is it possible somehow to modify the contents of the context.xml that eclipse uses
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like
Is it possible somehow to ask the user to allow cross-domain access instead of
while debugging a C++ program with GDB, is it possible somehow to add comments
is it somehow possible to call a rails function or to access a rails
Is it somehow possible to customize or subclass System.Windows.Forms.ColorDialog to add a few buttons?
Is it somehow possible to use the 'With' keyword on an existing object? I
Is it somehow possible to identify unused variables in a PHP file in Emacs?

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.