下面的代码在 Ubuntu 中运行良好,但我发现它在 Windows 中不起作用。
我有一个 unsigned char * 数组,我使用
将其写入文件unsigned char * data = NULL;
// code that sets the data and size etc
//////
saveFile.write( (char *)&data[ 0 ], width * height * 4 );
显示数据时,它很长,但最后只是空白。如果我将数据显示为 int,那么它只是 0。
for (int i = 0; i < width * height * 4; i++)
{
cout << int( data[i] ) << " ";
}
最后的产量
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
等等
当我将相同的文件加载到另一个程序运行的数据中时
data = new unsigned char[ width * height * 4 ];
readFile.read( (char *)data, width * height * 4 );
如果我显示我现在得到的数据的结尾
═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═
并显示为整数
205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205
显然有些东西不适用于 unsigned char * 到 char * 转换。这在 Ubuntu 中再次运行良好,但我在弄清楚 Windows 上发生了什么时遇到了很多麻烦。有人知道吗?此外,有谁知道如何让它正确保存和加载?