Thanks, I worked it out with resize().
- so I push back the header info in an empty vector
- I resize it to the right size
- then I read the file content just after the header info
It's very fast now. Do you think I still need reserve()?
It seem to work without it.
Code:
int main()
{
char * Buf2 = "C:\\a.txt";
char Buf3[260];
HANDLE hFile=CreateFile(Buf2,
GENERIC_READ,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,0,NULL);
cout << "File created... " << endl;
LARGE_INTEGER lpFileSize;
if(!GetFileSizeEx(hFile,&lpFileSize))
{
return 1;
}
long long iFileSize=lpFileSize.QuadPart, r;
int iWholeSize = 1 + strlen(Buf2) + 1 + iFileSize;
int iDigits = GetNumberOfDigits(iWholeSize);
iWholeSize += iDigits;
char szDigits[32];
itoa (iWholeSize, szDigits,10);
sprintf(Buf3, "%s*%s*", szDigits, Buf2);
vector<char> v;
/// ////////////////////////////
/// Insert header
for(int i = 0; i< strlen(Buf3); i++)
{
v.push_back(Buf3[i]);
}
v.resize(iFileSize+260);
/// ////////////////////////////
/// Read file
DWORD dwRead = 0;
if(!ReadFile(hFile, &v.at(strlen(Buf3)),
iFileSize,
&dwRead, NULL))