让我用代码问我的问题:
char* apples = "apples";
std::string str("I like .....");
// need to copy apples to str to have "I like apples", without creating new objects
Run Code Online (Sandbox Code Playgroud)
有分配功能,但遗憾的是似乎无法提供std::string offset.
我不想分配新对象,因为这是低延迟并且经常是代码的一部分.
UPD错,我已经把上述5点,但我的意思是6点,以适应"苹果"完美:)当然,如果串能力没有足够多的某些对象被创建.在我的问题中,我认为字符串容量就足够了.
您可以使用std::copy算法http://www.cplusplus.com/reference/algorithm/copy/
std::copy(apples, apples + sz, str.begin() + offset);
| 归档时间: |
|
| 查看次数: |
513 次 |
| 最近记录: |