【问题标题】:Reading binary from file to dynamicly allocated array从文件中读取二进制文件到动态分配的数组
【发布时间】:2014-02-24 18:41:57
【问题描述】:

快速提问:

我正在玩位图并尝试加载颜色表,但我得到了一个

 Access violation writing location 0xcccccccc.

在我将数组指针发送到读取函数之前,我动态分配了一个新数组。我只是想确认我这样做是正确的。

代码:

numColours = 1 << bitmapInfoHeader.biBitCount;
if( bitmapInfoHeader.biBitCount == 1 ||
    bitmapInfoHeader.biBitCount == 4 ||
    bitmapInfoHeader.biBitCount == 8){
    rgbquad = new RGBQUAD[numColours];
    in.read((char*)rgbquad, sizeof(RGBQUAD)*numColours);
}

【问题讨论】:

  • RGBQUAD结构是什么样的?
  • 你确定那不是有问题的代码部分吗?
  • 0xcccccccc 通常是未初始化变量的值,从这个例子中看不到。
  • @skreborn msdn.microsoft.com/en-us/library/windows/desktop/… deviantfan yh,但是我现在解决了,这是我的愚蠢错误。

标签: c++ arrays bitmap binary


【解决方案1】:

回答我自己的问题,是的,这是一种有效的方法!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-28
    • 2023-03-13
    • 2012-12-28
    • 2020-07-14
    • 1970-01-01
    相关资源
    最近更新 更多