I have two arrays in C++ and I’d like to append one to the end of the other such that:
char byte1[] = {0x00};
char byte2[] = {0x01};
Appending these two should yield {0x00, 0x01}. How would I do this? It’s simple enough in Java using System.arraycopy(), but I’m not sure what library would help me to accomplish this in C++ / C as I’m coding for a microcontroller.
If you’re using C, you can do:
If you want C++, don’t use the byte arrays in the first place. Use std::vector as it acts as an array that can track its own number of elements so you can feel more like you’re in the java world 🙂
A little warning though about C++ Vector Memory for Embedded:
You’re in a micro-controller, std::vector can waste alot of memory as it grows based on a multiple of current size. The more that’s in it, the more you could be wasting. Having said that, it’s a great class and as long as you know how it handles its memory its a great option.