I have this code:
#include<iostream>
void test(string in){
for(short i=0; i<in.length(); i++)
cout<<hex<<(unsigned short)in[i];
cout<<"\n";
string msg=in;
for(short i=0; i<msg.length(); i++)
cout<<hex<<(unsigned short)msg[i];
cout<<"\n";
msg+=(char)128;
for(short i=0; i<msg.length(); i++)
cout<<hex<<(unsigned short)msg[i];
}
int main(){
test("123456");
}
I expect the output to be:
313233343536
313233343536
31323334353680
But instead, it is the following:
313233343536
313233343536
313233343536ff80
It's clear that the += operator does something that i didn't count with. I use Code::Blocks on a 64-bit machine. How can I fix it?