tellp is returning the wrong value
In the following snipped, I am calculating a position for a file to seekp to, for writing.
I then try to print that position. It is returning an incorrect value;
printf("nXBlocks: %i nYBlocks: %i posX: %i, posY: %i, blockheight: %i, blockwidth: %i \n",
nXBlocks,nYBlocks, tilePosX, tilePosY , XBlockSize, YBlockSize );
binfile->seekp((tilePosX*poBand->GetYSize()*XBlockSize)*sizeof(uint16_t) + (tilePosY * XBlockSize*YBlockSize)*sizeof(uint16_t));
size_t pos = binfile->tellp();
cout<<"Multiplication output: "
<<(tilePosX*poBand->GetYSize()*XBlockSize)*sizeof(uint16_t) + (tilePosY * XBlockSize*YBlockSize)*sizeof(uint16_t)
<<endl;
cout << "Put pointer positions: " << pos << endl;
binfile->write((char *)&sixteenBitData, sizeof(uint16_t)*bufSizeX*bufSizeY);
I am getting a output o开发者_如何学运维f
Put pointer position: 18446744073709551615
For every call to the tellp
Instead of values based on the values I am passing to seekp
edit: some output of the first few...
nXBlocks: 34 nYBlocks: 29 posX: 0, posY: 0, blockheight: 1024, blockwidth: 1024
Multiplication output: 0
Put pointer positions: 0
nXBlocks: 34 nYBlocks: 29 posX: 0, posY: 1, blockheight: 1024, blockwidth: 1024
Multiplication output: 2097152
Put pointer positions: 18446744073709551615
nXBlocks: 34 nYBlocks: 29 posX: 0, posY: 2, blockheight: 1024, blockwidth: 1024
Multiplication output: 4194304
Put pointer positions: 18446744073709551615
seekp is apparently failing. It's likely that you are trying to seek to a point not in the file. Try getting the value
binfile.bad()
精彩评论