I have a string CorrAns = "Text", I want to replace a character at a particular position with a character from another string.
I used the following:
CorrAns.replace(1,1,OtherString.at(pos));
But its giving error, what is the best way to do this??
ecatmur :
replace has no overload taking size, size, char. You want\n\nCorrAns.replace(1, 1, 1, OtherString.at(pos));\n\n\nor\n\nCorrAns.replace(1, 1, OtherString.substr(pos, 1));\n",
2012-08-14T08:50:04
James Kanze :
Just use at (or the [] operator) accross the board:\n\ncorrAns[1] = otherString[pos];\n\n\n(Note that at rarely has the semantics you want. If a bounds error is\na precondition failure, as is usually the case, the last thing you want\nis an exception.) ",
2012-08-14T08:49:01
Naidu Ypvs :
Your syntax is wrong. There are several methods for replace() function. Check below :\n\nhttp://www.ansatt.hig.no/frodeh/ooprog/string2.html",
2012-08-14T08:49:25