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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:36:13+00:00 2026-06-10T23:36:13+00:00

I have the following code and when I compiled and went, I got following

  • 0

I have the following code and when I compiled and went, I got following message

terminate called throwing an exceptionAbort trap: 6

I looked for this ,but I was not able to understand this error message. Please tell me, what this error message means and how I fix the code.
Here is the code:

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

int main(){
    int n,r;
    while(cin>>n>>r){
        if(n==0&&r==0)break;
        string s;
        for(int i=0;i<n;i++)
            s[i]='i';

        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            string left=s.substr(p-1,p+c-1);
            string right=s.substr(0,p-2)+s.substr(p+c, (int)s.size());
            s=left+right;
        }
        cout << (int)(s[0]-'0')+1 << endl;
    }
        return 0;
}

compile with g++, on Mac OSX 10.7.4

  • 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-10T23:36:14+00:00Added an answer on June 10, 2026 at 11:36 pm

    Don’t know where the exception comes from, but this just doesn’t work

    string s;
    for(int i=0;i<n;i++) 
        s[i]='i';
    

    because the string is initially empty, and all s[i] will be out of bounds.

    To add characters to the string in a loop, try

    string s;
    for(int i=0;i<n;i++) 
        s.push_back('i');
    

    If you just want a string with lots of 'i's, you can do that when constructing it:

    string s(n, 'i');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a DLL using the following code. I have compiled this code
I have the following code compiled by gcc: #include <iostream> using namespace std; class
I have the following line of code which when compiled with GHC it goes
I have the following code, which compiles but doesn't bring back any data. Here
I've got a simple question for you :) I have the following Scala code,
I have the following code: struct Message { explicit Message(const std::string& message) : selfMessage(message)
I have the following code fragment that I use to scale images. This is
I have the following code, but the compiler says sender_wrapper is undefined, even though
I have the following code that calls the function uint32_pack. This program compiles with
i have the following code compiled with GCC 4.2 / XCode. template <typename T>

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.