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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:58:22+00:00 2026-06-13T02:58:22+00:00

I am trying to make a code to allow the user to enter a

  • 0

I am trying to make a code to allow the user to enter a very huge number “bigger than the size of the normal “int” , so am trying to take the user input as a string and take each value from the string and pass it to an int e.g. s="3786473646768" so int will take each value and save it in a vector.

This is a very simple syntax I enter the two strings but if they aren’t equal it gives me a window saying “Expression: String Subscript is out of range”
Any help please ?

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

  int val1=0,val2=0,val3=0,val4=0;
  string i,p;
  vector <int>add;
  vector <int>sub; 
  cout<<"Enter a number: "<<endl;
  cin>>i;
  int sizei=i.length();
  cout<<"Enter a number: "<<endl;
  cin>>p;
  int sizep=p.length();

  for (int n=0; n<sizei; n++)
   {
     val1=int(i[n]);
     val1=val1-48;
     val2=int(p[n]);
     val2=val2-48;
     val3=val1+val2;
     val4=val1-val2;
     add.push_back(val3);
     sub.push_back(val4);
   }
  cout<<"\n";
  for(unsigned int a=0;a<add.size();a++)
      cout<<add.at(a);
  cout<<"\n";
  for(unsigned int a=0;a<sub.size();a++)
      cout<<sub.at(a);
    system("pause");
    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-06-13T02:58:23+00:00Added an answer on June 13, 2026 at 2:58 am
    for (int n=0; n<sizei; n++)
    

    Within this loop, the value of n goes from 0 ... sizei - 1

    However, if sizep is less than sizei - 1, it will try to access p[n] or equivalently, p[sizei-1], which is outside the bounds of the string you declared.

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

Sidebar

Related Questions

I am trying to make a query in Codeigniter that will allow a user
I'm currently trying to make a GreaseMonkey script that will allow a user to
I'm trying to make a code that will show two different images depending on
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I am trying to make my code more clear using the include function of
2 short questions based on trying to make my code more efficient (I think
im totally new when it comes to trying to make HTML code. I was
I'm trying to make a genric code to serialize and deserialize any object that
I am trying to make a frame from code so that I can apply
I'm trying to make a part of my code more fluent. I have a

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.