我正在尝试使用函数将C字符串转换为std :: string。该功能可在64位上正常运行gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
。但是,当我使用它进行编译-O2
或-O3
优化时,它会出现段错误。它的工作原理与-O1
虽然。有人可以提出修复建议或解决方法吗?功能如下:
void make_name(unsigned const &i, string &h_file)
{
char h_str[10];
sprintf(h_str, "tmp/%09d.hb", i);
h_file = string(h_str);
}
简单:提供足够的缓冲区。或使用std::stringstream
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句