简体   繁体   中英

C++ - How do I append a char to a char[]?

I am trying to append a char to the end of a char array:

char szBuffer[MAX_PATH];
if(SHGetSpecialFolderPathA(HWND_DESKTOP, szBuffer, CSIDL_PERSONAL, FALSE)){
    szBuffer[sizeof(szBuffer)] = "\\";
}

I know that will not work correctly, but I am unsure how to do it. Also, how would I append a string?

You can use strcat , like this:

strcat(zsBuffer, "\\");

This assumes that MAX_PATH has enough space to fit the string with the appended character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM