I have a char buffer of length 50 bytes. In this buffer, at 20-21 bytes, I want to write a short number, of size 2 bytes, say -1234, specifically at those bytes only? How can I do that?
Looks trivial. Not sure whether this is what you want.
#include <cstring>
char* pc = ...;
short num = ...;
std::memcpy(pc + 20, &num, 2);
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.