I have a std::vector of short ints that I need to write to a specific location in a binary file (without using .NET code). To that end, I wrote up this code:
    ofstream fileStream (filePathString, ios::out | ios::binary);
    int curPos = 2821;
    int iter = 0;
    while (iter < 1024*1024){
        char bytesToWrite[2];
        //Low byte
        bytesToWrite[0] = LOBYTE(dataVector[iter]);
        //High byte
        bytesToWrite[1] = HIBYTE(dataVector[iter]);
        fileStream.write(&bytesToWrite[0], 2);
        curPos += 2;
        delete[] bytesToWrite;
The code runs without crashing, but when I look at the file afterwards in a hex editor, every byte (even those outside the range I thought I was writing to) are replaced with 00. I suspect I'm missing something in my understanding of file streams. Did I write that code correctly? Seekp does move the pointer over the next byte to be overwritten, yes? Am I getting a memory leak somewhere?