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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:29:36+00:00 2026-05-30T10:29:36+00:00

SO here in my function string chopstring(string& tocut, List test[26]){ string totoken = ;

  • 0

SO here in my function

string chopstring(string& tocut, List test[26]){
    string totoken = "";
    while(tocut[0] == ' ' || tocut[0] == 10 || tocut[0] == 13){
        tocut.erase(0);
    }
    int finish = 0;
    finish = tocut.find(" ", 0);
    if (finish == string::npos){
        cout << "NPOS!" << endl;
        for(int i = 0 ; i < 26; i++)
        test[i].Print();
    }
    for (int i = 0; i < finish; i++){
        totoken += tocut[i];
    }
    string::iterator start = tocut.begin();
    string::iterator end = tocut.begin() + totoken.length();
    tocut.erase(start, end);
    return tokenize(totoken);
}

Im having trouble with the string::erase. It deletes the entire string? Any suggestions? Id like to learn the reason too so please explain if you know.

it’s being called in another function that stored the returned token in a linked list, then calls this function again untill the string (tocut) is empty. The first line it feeds in is
“The Time Traveller (for so it will be convenient to speak of him)”.
What happens right now is that it takes the first “The”, tokenizes it, and does it’s thing, but the tocut.erase(start, end), deletes the whole string, and causes the program to crash.

  • 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-30T10:29:37+00:00Added an answer on May 30, 2026 at 10:29 am

    Do below:

        while(tocut[0] == ' ' || tocut[0] == 10 || tocut[0] == 13){
            tocut.erase(0,1);   // see cpp reference. For single argument it takes iterator
        }
    

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

Sidebar

Related Questions

Here is a simple function that converts a string to an integer. int str2int(char
Here is my function ( updated ): Public Shared Function shortenUrl(ByVal URL As String)
Here is a function I wrote to break a long string into lines not
I've got a function here that is meant to look through a list of
I can only seem to find how to return arrays from my function. Here
Here is the code <script> String.prototype.testthing = function() { return working; } alert(String.testthing()); </script>
I am trying to use the find function here. For that here's the code
According to a function here, http://www.unicodetools.com/unicode/convert-to-html.php , the function is used to convert string
Is it possible to have default arguments in MATLAB? For instance, here: function wave(a,
Here is function , <script type=text/javascript> $(document).ready(function() { getRecordspage(1, 5); $(a.page-numbers).click(function() { alert(1); getRecordspage($(this).text(),

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.