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