string increment(string s, int loc) {
char c = s[loc];
c += 1;
s[loc] = c;
return s;
}
increment("A", 0);
returns Segmentation fault
at s[loc]=c;
and I have no idea why.
Is there a specific function to replace a character?
Edit to further simplify:
string a="ABC";
a[1]= 'D'; //returns Segmentation fault
a[0]=a[1]; //returns Segmentation fault
It is as if strings are 'read-only'