'When I run the program, I don't get any errors, but after I have already set the value of the variables, I get this error

When I run the program, I don't get any errors:

image

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    string s1, s2, s3;
    cout<<"S1 = ";
    cin>>s1;
    cout<<"S2 = ";
    cin>>s2;
    cout<<"S3 = ";
    cin>>s3;

    for(int i=0; i<=s1.size(); i++){
        if(s1[0]==s2[0]){
            s1.append(s3, i, 1);
           // s2.assign(s3, i, 1);
        }
        else{
            break;
        }
    }

    cout<<"S1: "<<s1<<endl;

    return 0;
}

But after I have already set the value of the variables, I get this error:

image

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source