除了(显而易见的)首先构建 C 样式字符串然后使用它创建 std::string 之外,是否有更快/替代/“更好”的方法从字符向量初始化字符串?
好吧,最好的方法是使用以下构造函数:
template<class InputIterator> string (InputIterator begin, InputIterator end);
这会导致类似的结果:
std::vector<char> v;
std::string str(v.begin(), v.end());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)