string decode

Hello,

I was working on string decoding. Given a decoded string Q need to find the original string P. The equation for original string is given as P[i] = Q[i-1] - P[i-1] - P[i-2] except for P[0] and P[n]. If I consider P and Q as std::string, I couldnt assign value for P at each position. For example,

P[0] = 0;
for(int i=1;i<(Q.size()-1);i++){
P[i] = Q[i-1] - P[i-1] - P[i-2];
}

I could not implement the above equation. Is there a way to access each individual value of P?

Thank you in advance
Accessing chars in a std::string can be done with .at()
Topic archived. No new replies allowed.