0
Changing String Variables into int in C++
I was trying to change a variable called username in my code. This is what it looked like: string username = "name"; username = 1; cout<<username; And once I ran that code, it had an output of a ? in a box. I am wondering how to fix it, not what the ? in a box means.
2 Answers
+ 2
What output were you expecting?
â° indicates that the character cannot be displayed by the character set you are using.
Despite it being supposed to raise a compilation error, it doesn't output anything for me on Sololearn playground (Android).
0
The compiler will try ti cast an int to char then create a string from latter.
In practice, assigning an int to string will create first a char having the int ascii code the will be created a string with that char.