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

The Archive Base Latest Questions

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

The standard library provides std::advance , but that only advances an iterator to a

  • 0

The standard library provides std::advance, but that only advances an iterator to a given offset.

Writing that algorithm yourself is pretty trivial:

template<class Iter, class T>
void advance_until(Iter& it, Iter end, T const& delim){
  while(it != end && *it != delim)
    ++it;
}

Or even:

template<class Iter, class T>
void unsafe_advance_until(Iter& it, T const& delim){
  while(*it != delim)
    ++it;
}

Which would more closely model the way std::advance behaves.

Usage example:

std::string s("hello world!");
std::string::iterator it(s.begin());
advance_until(it, s.end(), 'w');
//unsafe_advance_until(it, 'w');
if(it != s.end())
  std::cout << *it << '\n'; // prints 'w'

But maybe there’s already something like that in the standard library or Boost, so I thought I’d ask away.

  • 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-27T05:27:26+00:00Added an answer on May 27, 2026 at 5:27 am

    This is commonly known as std::find():

    std::string::iterator it = std::find(s.begin(), s.end(), 'w');
    
    if (it == s.end()) { /* not found */ }
    else               { /* found *it */ }
    

    Successive items can be found through a loop:

    while (it != s.end())
    {
      // ...
      ++it; // always valid
      it = std::find(it, s.end(), 'w');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a C++ Standard Template Library class that provides efficient string concatenation functionality,
In standard library, I found that namespace std is declared as a macro. #define
The standard Ruby library io/wait provides a method on IO objects ready? that returns
Is there a standard implementation or library that provides a GUI toggle switch in
Is there a standard library method that converts a string that has duration in
Is there a class in the standard library of .NET that gives me the
I have the following problem that the standard library doesn't solve well, and I'm
I'm looking for a C library that provides generic collection data structures such as
I am writing a library that I would like to be portable. Thus, it
Java provides java.io.Serializable and java.lang.Cloneable in his standard library (and special support for it

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.