I have a string a = "Hello world!", now for fun I wish to change the first letter in the string a to a number of my choosing. for example
string a = "Hello world!"; int x; std:cin>>x; a[0] = x; cout << a; Now what i want it to produce is "xello world!" x being the number i typed in, but instead I get a little smiley face.
Anyone seen anything similar and know how to fix it?
Also: Why can you even access a string like this string[] ? it's not a char array o.o
123, do you want the result to be123ello world!?a[0]='0'+x. you should learn about en.wikipedia.org/wiki/ASCIIstd::string::operator[]overload in fact returns achar&.char x = 'a'; x = 100;and see what happens.