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

  • Home
  • SEARCH
  • 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

first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
Okay so im working on this php image upload system but for some reason
OKay first off this is really really similiar to the http://dribbble.com homepage. In the
(First off, thanks so much. Stackoverflow has been very helpful to me in the
I've been trying to setup my first rails app--I'm okay at stumbling around on
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
Okay this is a fairly broad question. This is my first App and I'm
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay I have two classes for two links and two divs with different information.
First off, I would just like to mention my absolute hatred of Internet Explorer

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.