USACO Censoring - CPP Variable Assignment Question

Problem Info

USACO Censoring

Question

How are the following different in CPP
Option 1 : O += S[i];
Option 2: O = O + S[i];
My understanding was that both are same and just syntax are different. But option 2 fails. I don’t know why a syntax difference would fail my code ?

What I’ve Tried

I have tried both the above options.

My Work

#include <iostream>
#include <vector>

using namespace std;

//const int PRIME = 49037;
//const int MOD = 1e9 + 7;



// Driver code
int main() {
 
    //char T[100];
    string T;
    string S;  //,T;
	cin >> S;
    cin >> T;
    string O = "";

    int t_size = T.size();
    for (int i = 0; i < S.size(); i++) {
        O += S[i]; //Passed
       //O = O + S[i];  (Failed)
        int o_size = O.size();
        if (o_size>=t_size && (O.substr(o_size-t_size) == T ))
        {

            O.resize(o_size-t_size);
        //    cout << "O resized ===== "<<O << endl;
        }
    }
    
    cout << O << endl;

    return 0;
}


https://codeforces.com/blog/entry/66660?#comment-506931

Thank you . I will read it in details.