Doubt related to strings in C++

I have seen this many times that I am unable to cout a string whose elements have been changed or a new string has been formed like in the below case. Please explain. Please correct me if I am wrong.

@N4i9kita

  1. you have declared a string of size of zero. i.e ans is a empty string and you accessing ans[0].
  2. you can simple do ans += s[i]
  3. when using string, you dont have to add ‘\0’
  4. to declare a string of size lets say 100, you can do string ans(100, ’ ');

Thank you so muchh. :grin:

1 Like