tellp返回错误的值

时间:2011-09-14 20:20:16

标签: c++

在下面的剪辑中,我正在计算要搜索的文件的位置,以便写入。

然后我尝试打印那个位置。它返回的值不正确;

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);

我得到了

的输出

放指针位置:18446744073709551615

每次调用tellp

而不是基于我传递给seekp的值的值

编辑:前几个的一些输出......

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

1 个答案:

答案 0 :(得分:0)

seekp显然是失败的。您可能正试图寻找不在文件中的点。尝试获取值

binfile.bad()