gpt4 book ai didi

c++ - tellp 返回错误的值

转载 作者:太空宇宙 更新时间:2023-11-04 14:21:25 26 4
gpt4 key购买 nike

在下面的片段中,我计算了一个文件的位置,以便写入。

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

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

最佳答案

seekp 显然失败了。您可能正在尝试查找文件中不存在的点。尝试获取值

binfile.bad()

关于c++ - tellp 返回错误的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7422480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com