hello everybody
i made a little program to create a binary file from elements in a vector.
i'd like to know if it's safe to do it the way i did (writing lots of elements at once) or if i should write one by one to the file.
As long as you are using C++03 or greater compiler the standard guarantees a vector will be in a contiguous block.
What is the purpose to that static_cast in your loop? Your vector is a vector of uint8_t not of a size_t. Since the size_t is probably larger than an uint8_t, you're explicitly upcasting to the size_t then implicitly downcasting to the uint8_t.
Also you have an out of bounds error in that loop as well. Remember vectors, much like arrays, start at zero and stop at size - 1.
Lastly shouldn't you be using sizeof(vec[0]) in the write() as well?