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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:01:24+00:00 2026-05-27T07:01:24+00:00

I need to search an array of c-strings for a substring. I created what

  • 0

I need to search an array of c-strings for a substring.

I created what I thought would return me the answer but it is only syntactically correct but semantically wrong, but I’m not sure where I have gone wrong.

There is also a sub-question to this. Which I will ask after showing you the example I tried.

#include <boost/algorithm/string/find.hpp>

const char Months[12][20] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

void Test()
{
    typedef boost::iterator_range<boost::range_iterator<const char [20]>::type > constCharRange;
    boost::iterator_range<char const *> ir = find_first("January", months);
}

ir.first == ir.last

The results of the iterator show that I have not written this correctly.

I’m not sure whether the fact that the first parameter is actually const char [8] is having a detrimental effect.

My main question what should I do to correct it, and the supplemental question is how can I extract the type that find_first requires from constCharRange or indeed any such typedef.

Edit:

I see that I have used end incorrectly. I’ve then managed to get slightly different example to work however they are not compatible with the definitions I actually have to use (I can add to the code but not change the existing definition).

const std::string Months[]= { /*same data as before*/
void StringTest2()
{
    const std::string* sptr =0;
    sptr = std::find(boost::begin(Months), boost::end(Months), std::string("February"));
    if (sptr)
    {
        string sResult(*sptr);
    }
}

Another Test

const char* Months[]= { /*same data as before*/
void StringTest3()
{
    const char **sptr = std::find(boost::begin(Months), boost::end(Months), "February");
    if (sptr)
    {
        string sResult(*sptr);
    }
}

Here is the nearest I can get, but I can’t seem to get the return type spec correct

void StringTest4()
{
    const char Months[12][20]Months[]= { /*same data as before*/
    std::find(boost::begin(Months), boost::end(Months), "February");
}
  • 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-27T07:01:25+00:00Added an answer on May 27, 2026 at 7:01 am

    I can correct StringTest4 to do exact matches, however this solution won’t work for partial ones.

    void StringTest4()
    {
        boost::range_iterator<const char [12][20]>::type sptr = std::find(boost::begin(Months), boost::end(Months), std::string("February"));
        if (sptr)
        {
            string sResult(*sptr);
        }
    }
    

    Note the passing of std::string rather than just "February" if we don’t do this then std::find will just be doing a pointer comparison which would therefore result in failure.

    I would still prefer to use this with string_algo, but I’m still not sure which bits I would need for it to successfully work with const char Months[12][20]

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

Sidebar

Related Questions

i need to search in the thousands strings of a array for the character
I need to search a string in the string array. I dont want to
I have a multidimensional array. I need to search it for a specific range
I need to search a file for a word and return the whole line
So I've written a little binary search function (not that I need to, but
I have an array of strings, and a Linq query: /// <summary> /// Return
What does array_search() return if nothing was found? I have the need for the
I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount%
I need to search across multiple columns from two tables in my database using
I need to search for all users containing a certain text string in their

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.