插入一个字符串到另一个字符串中有效 [英] Insert a string into another string efficiently

查看:135
本文介绍了插入一个字符串到另一个字符串中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符AA [] = {你好,! };

BB的char [] = {世界};

如何插入到BB AA最有效地CString的?

How to insert bb into aa the most efficiently with cstring ?

推荐答案


  • 分配足够大的缓冲区(的malloc / 新[]

  • 的AA字符串的第一部分复制到缓冲区中(函数strncpy / 的memcpy

  • 复制BB的字符串(的strcpy / 的memcpy

  • 复制AA字符串的其余部分(函数strncpy / 的memcpy

  • allocate big enough buffer (malloc/new[])
  • copy the first part of the aa string into the buffer (strncpy/memcpy)
  • copy the bb string (strcpy/memcpy)
  • copy the rest of the aa string (strncpy/memcpy)
  • 这篇关于插入一个字符串到另一个字符串中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆