So it is tempting to do this:
char buf[1024] = "this is"; std::sprintf(buf, "%s test", buf); But it is undefined behaviour. I suppose it can be solved via temporary:
char buf[1024] = "this is"; std::sprintf(buf, "%s test", std::string(buf).c_str()); What are the downsides of this approach?
strcpy(in this case);sprintf(buf + strlen(buf), " test");. You should also consider using the safer versions (sprintf_s).std::stringinstead of achar[]to begin with:string buf = "this is"; buf += " test";sprintf_sis not any safer thansprintf, as well as not being widely supported.snprintfwould be a better optionsnprintfbut the wrong function name came to mind. Sigh.