Random access of Binary Files

Hello all, first post here so be gentle,

I'm having some trouble trying to do random access on binary files. Following is a description of what I'm trying to accomplish:

First, I am declaring a wofstream to a binary file like this:

wofstream randomSearchFileListOut(L"TestScheduler_TempFileList.bin", ios::out | ios::binary);

Part of a program I am writing will look at a directory and generate a list of file paths for all files in that directory, including the files in its subdirectories. I am putting this information inside the aforementioned binary file with the wofstream like this:

randomSearchFileListOut.write(fullPathBuffer, MAX_PATH * sizeof(wchar_t));

Above, fullPathBuffer is a wchar_t array of size MAX_PATH.

Once all the file paths are written, I declare an int vector with the same size as the number of files found and shuffle it randomly. Now my plan is to read from the text file I just wrote randomly with a wifstream using random access to go through these files in random order. I'm trying to do it like this:

randomSearchFileListIn.seekg(filesToBeProcessed[i] * MAX_PATH, ios::beg);
randomSearchFileListIn.read(buffer, sizeof(wchar_t) * MAX_PATH);

Above buffer is, again, a wchar_t array of size MAX_PATH. Can anyone see anything I'm doing wrong? What I want is to read in a segment equivalent to a full file path each time I read, regardless of how long the file path actually is.
Last edited on
How about:

randomSearchFileListIn.seekg(filesToBeProcessed[i] * MAX_PATH * sizeof(wchar_t), ios::beg); ?
Topic archived. No new replies allowed.