string str1="1234.56";
char ch[str1.length()+1];
double dtude=atof(str1.c_str());
sprintf(ch, "%.5f", dtude);
cout<<ch<<endl;
运行的结果为:1234.56000
但是实际上,ch的大小是8,却存储了10个元素。valgrind 也没有检测到内存非法读写的问题,运行都正常,有大神知道这是什么原因吗?
string str1="1234.56";
char ch[str1.length()+1];
double dtude=atof(str1.c_str());
sprintf(ch, "%.5f", dtude);
cout<<ch<<endl;
运行的结果为:1234.56000
但是实际上,ch的大小是8,却存储了10个元素。valgrind 也没有检测到内存非法读写的问题,运行都正常,有大神知道这是什么原因吗?