   Efficient writing contents of a vector to binary file using ofstream?
  Im trying to write the contents of a vector containing shorts to a binary file. I could iterate the vector and write the shorts 1 by 1 but it would be inefficient. Previously when i used arrays, i would just get the pointer to the first element and write (arrayLength * sizeof(arrayType)) bytes to the file. But i believe i cant do so with vectors since they might contain additional class member variables.Since the STL is supposed to work well with it's own components, i believe there must be a better way to do so.   
  now this is going against STL's purpose, but you could easily do what you were doing with your arrays with your vector doing something like this:write( (char * )&vector[0], vector.size() * sizeof( short ) );;  For exactly this reason the standard guarantees that all elements in a vector are stored in contiguous memory.  Simply take the address of element 0 and write exactly the way you used to with arrays.Alan   