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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:11+00:00 2026-05-23T23:09:11+00:00

I know this problem crops up a lot, but I couldn’t find a piece

  • 0

I know this problem crops up a lot, but I couldn’t find a piece of code which worked for me.

I am trying to strip all punctuation off of an incoming string using find_first_not_of and find_last_not_of methods in the string library:

//
//strip punctuation characters from string
//
void stripPunctuation(string &temp)
{
    string alpha = "abcdefghijklmnopqrstuvwxyz";

    size_t bFound = temp.find_first_not_of(alpha); 
    size_t eFound = temp.find_last_not_of(alpha);

    if(bFound != string::npos)
        temp.erase(temp.begin());
    if(eFound != string::npos)
        temp.erase(temp.end());
}

Basically, I want to delete anything at the front of the string that is not alphabetic and anything at the end of the string which is not alphabetic. When this function gets called, it results in a segmentation fault. I am not sure where I should be passing bFound and eFound?

  • 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-23T23:09:13+00:00Added an answer on May 23, 2026 at 11:09 pm

    Never pass .end(). It points to an invalid iterator, which represents the end.
    If you want to delete the last character in a string, use temp.erase(temp.length()-1).
    If I understand you correctly.

    edit:

    it seems erase() only accepts an iterator, which is what i thought initially.

    That is not true:

    string& erase ( size_t pos = 0, size_t n = npos );
    iterator erase ( iterator position );
    iterator erase ( iterator first, iterator last );
    

    http://www.cplusplus.com/reference/string/string/erase/

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

Sidebar

Related Questions

I know I've solved this problem before, but I can't remember or find the
I know this question has been asked before, but I ran into a problem.
I don't know if anyone else even has this problem, or has noticed, but
I know I've had this problem before so I'm really frustrated. I've got the
Anyone know how to solve this problem? 03-23 13:03:20.585: WARN/googleanalytics(3430): Problem with socket or
I came across this problem while preparing for an interview and curious to know
I'd like to know if there's a better approach to this problem. I want
I don't know where to look for about this problem ... I have three
I have solved this problem, I just need to know what to do. I
OK. This problem is doing my head in. And I don't know if there

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.