Most of the code would be simplified to:
if(event.key.keysym.unicode != 0) {cpp_main_string += event.key.keysym.unicode;}
You'll have to be careful about the extra bits given in the unicode
code and deal with it by (for example) converting to UTF-8, filtering
out non-ascii, or using std::wstring.