char comment[32] = "test#20170420|0420"; char *pos = strchr(comment, '#'); char front[32]={0}; char back[32]={0}; char newComment[32] = {0}; memcpy(front, comment, pos-comment); strcpy_s(back, pos); sprintf_s(newComment, "%sC%s", front, back); std::cout<<newComment<<endl;
任何new内存都是消耗的,正确的做法是使用memcpy