【发布时间】:2016-02-19 21:28:02
【问题描述】:
像素是一个包含 3 个字符的结构。
struct Pixel { char r, g, b} ;
int H = 5, C = 10;
Pixel *PMatrix[H]; // Creates an array of pointers to pixels
for (int h = 0 ; r < H ; h++) {
PMatrix[r] = new Pixel[C]; //Each row points to an array of pixels
}
我有一个 PPM 文件,我正在尝试将字节逐行读取到我的像素矩阵中以进行图像表示。
for (unsigned int i = 0; i < height; i++){
cin.read(PMatrix[i][0], width*3);
}
我也在循环中尝试了"cin.read(PMatrix[i], width*3);"。
我收到错误no matching function for call to 'std::basic_istream<char>::read(PpmImage::Pixel&, unsigned int)'
这是什么意思???
【问题讨论】:
-
与使用数组无关,与尝试传递用户定义的类型(
Pixel)有关。read可能不适合您。 cplusplus.com/reference/istream/istream/read -
它应该是
&PMatrix[i][0]或只是PMatrix[i]加上一些reinterpret_cast<char*>。但我猜它在运行时仍然会失败(因为对齐?)