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.
Doubt related to strings in C++
- you have declared a string of size of zero. i.e ans is a empty string and you accessing ans[0].
- you can simple do ans += s[i]
- when using string, you dont have to add ‘\0’
- to declare a string of size lets say 100, you can do string ans(100, ’ ');
Thank you so muchh.
1 Like