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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:47:44+00:00 2026-05-22T19:47:44+00:00

Okay so first off, Im pretty new to programming, Ive only read a bit

  • 0

Okay so first off, Im pretty new to programming, Ive only read a bit of stuff and have been working on some project Euler problems to kind of wrap my head around concepts and such. However, I got an error message today that I couldn’t make any sense of so I thought I would ask here for some help! Any links or advice is appreciated!

Here’s the error message:

terminate called after throwing an instance of 'std::out_of_range'  
what(): basic_string::substr Aborted

So any advice you might have would be awesome! If you need to see my code or have questions, ask! Though I”d rather try to understand the problem then find the answer myself! Thanks!

EDIT: Okay since you guys say you would need to see the code here it is.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int stringtoint(string s_convertee)
{
    int i=0;
    istringstream sin(s_convertee);
    sin >> i;
    return i;
}


int main()
{
string s_testnum = "233456091289474545356";
int n_maxmult = 0;
for (int i = 0; i<s_testnum.length(); i++)
  {
      int n_product = 1;
      for (int j = i; j<(i+4); j++)
      {
          string s_multiplier = s_testnum.substr(j, 1);
          int n_multiplier = stringtoint(s_multiplier);
          n_product *= n_multiplier;
      }
      if (n_product>n_maxmult)
      {
          n_maxmult = n_product;
      }

  }
return 0;
}
  • 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-22T19:47:45+00:00Added an answer on May 22, 2026 at 7:47 pm

    As other answers have already pointed out, in substr

    If the position passed is past the end of the string, an out_of_range exception is thrown.

    In your code:

    for (int j = i; j<(i+4); j++)
    

    When i is 1 less than s_testnum.length() j goes past s_testnum.length() and when you do, s_testnum.substr(j, 1); causes an out_of_range exception.

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

Sidebar

Related Questions

Okay so I have two import pieces of code involved in this. This first
Okay I have my csv builder essentially working. it has 3 columns. Name, Position,
Okay, I've written my first functional PHP extension. It worked but it was a
Okay, I'll be the first to admit that i'm quite terrible when it comes
Okay, so I have a snippet of code from a website containing a button:
I am working on deprecating a set of Java classes so they aren't used
I have a service that talks to other services on the same machine over
Okay so I was board and wondered how fast math.h square root was in
Apologies for the title, I found it hard to define my question succintly and
How could I compile a .cs program that references a COM DLL from the

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.