I would need a dynamic pointer string at the end and i know that with sprinf and family i should use a char array.

Its compiling and working this way but i prefer to ask you if its ok to do it like this because i know that with pointers we can have undefined behaviour.

Code:
int main ()
{
    char * buffer = (char*) calloc (512, sizeof(char));
    char * str = "hello ";
    sprintf (buffer, "\n%s%s", str, "world\n");
    cout << buffer << endl;
    free(buffer);
    return 0;
}