Please tell what is the problem in this code?

I think the method is correct but not getting any output.

Hey @sahilkhan2312000131

    using namespace std;

    int main() {

       int t;

        string a,b;
        string c(a.length(),' ');//initializimg c with space of required length
        for(int i=0;i<a.length();i++){

                c[i]='0';//= instead of ==
                c[i]='1';//= instead of ==




        return 0;

If this resolves your query then please mark it as resolved :slight_smile:

Why do we have to create c with a well defined size??
We can simply make a normal string.

Because you are using c[i] to reference i th character which we can only do if it exist .

So either declare string like this or use + or push_back to append in string

1 Like

thank u so much kartik

1 Like