Insert a string into another string efficiently

后端 未结 4 1824
清歌不尽
清歌不尽 2021-01-07 05:10

I have

char aa[] = { \"Hello, !\" };

char bb[] = { \"World\" };

How to insert bb into aa the most efficiently with cstring

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 05:27

    • 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)

提交回复
热议问题