gpt4 book ai didi

c++ - 从 P6 PPM 文件读取字节到字符数组 (C++)

转载 作者:行者123 更新时间:2023-11-28 05:49:54 25 4
gpt4 key购买 nike

<分区>

相关代码如下:

string s;
int width, height, max;

// read header
ifstream infile( "file.ppm" ); // open input file
infile >> s; // store "P6"
infile >> width >> height >> max; // store width and height of image
infile.get(); // ignore garbage before bytes start

// read RGBs
int size = width*height*3;
char * temp = new char[size]; // create the array for the byte values to go into
infile.read(temp, size); // fill the array

// print for debugging
int i = 0;
while (i < size) {
cout << "i is " << i << "; value is " << temp[i] << endl;
i++;
}

然后,我得到的输出表明数组中的值要么为空,要么为“?”。我想这意味着字节没有正确转换为字符?

i is 0; value is

i is 1; value is

i is 2; value is

i is 3; value is ?

i is 4; value is ?

...等等

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