In one of my project, i initialized a const std::string& with a const char (know at compile time), and the result of print it was ... surprising.
I use gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) on Ubuntu 12.04x32
Exemple:
#include <string> #include <iostream> using namespace std; class A { public: A() : str("test"){}; const string& str; }; int main(int argc,char* argv[]) { A a; cout<<a.str<<endl; return 0; }; So, normaly, it will show "test" but, this is a prt of the output I have:
testP�����utf8)����lower_case_table_names�xW�xW� �� ����127.0.0.1utf8W�Y127.0.0.1 via TCP/IP127.0.0.1 �5.5.31-0ubuntu0.12.04.1rootW�rootW�1����metadata_use_info_schema!P�XP�� VARaءpW�P4:����SHOW SESSION VARIABLES LIKE 'lower_case_table_names'`(���TCP/IP (3)@!K!K!� ..... <charset name="gb2312"> <family>Simplified Chinese</family> <description>GB2312 Simplified Chinese</description> <alias>chinese</alias> <alias>iso-ir-58</alias> <collation name="gb2312_chinese_ci" id="24" order="Chinese"> <flag>primary</flag> <flag>compiled</flag> </collation> <collation name="gb2312_bin" id="86"> <flag>binary</flag> <flag>compiled</flag> </collation> </charset> the output continu for 1000 lines.
So my question is simple: WHY? (I try to add a \0 at the end of "test", but no change)