C ++:将C字符串转换为std:string

静止的

我正在尝试使用函数将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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章