Question when copying two sentences to a string pointer using the C++ strcpy_s function

Asked 2 years ago, Updated 2 years ago, 43 views

When combining two strings in the char*pszResult inside the function Add(charpszLeft, char pszRight),

int nLenLeft = strlen(pszLeft);

int nLenRight = strlen(pszRight);

char *pszResult = new char[nLenLeft+nLenRight+1]; after allocating memory like this,

To copy strings to newly allocated memory

strcpy_s(pszResult, nLenLeft + 1, pszLeft);

strcpy_s(pszResult+nLenLeft, nLenRight + 1, pszRight);

I write a function like this, but I don't understand what the first strcpy_s function is about, and I don't understand why the second strcpy_s function contains "pszResult+nLenLeft" I understood that I would copy the memory address of the pszResult by doing the pointer operation as much as nLenLeft, is that right? Or is it a different reason?

strcpy

2022-09-21 19:37

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.