Generate Parenthesis, using string stl, instead of array of char, but output is coming wrong..why?

code in this code, i used string… instead of array of char, can anyone help he figure out where i am going wrong or what changes should i make in my code… thx in advance