The std::string includes an overloaded operator= , which takes a char value. Since char is an integer type, int implicitly converted to char .
The value assigned to str is not an empty string; it is a string of length 1, in which one character has a value of 2 (Ctrl-B).
Try feeding your program output to cat -v or hexdump .
$ ./c | cat -v Acquired value: '^B'
source share