How to insert the difference i.e. ineger in a string?

How to insert the difference i.e. ineger in a string ?

Hi @namandubey20
Suppose you have a string s and a interger x which you want to insert in string at position 2. So you have to do following :
s[2]=x+β€˜0’;
This is how at 2nd position your integer x will be placed in the string.

But der sir in this case my s[2] element will be replaced by x, which I don’t want.

Okay in that case your have to use substr as following :
char p=x+β€˜0’;
s=s.substr(0,i)+p+s.substr(i,s.size()+1);

where x is the int value which you want to insert and s is the string and i is the index at which you want to insert the integer.

Hi @namandubey20
Is your doubt resolved ?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.