Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;PGM文件在读取中间的每个字符中读取默认值为38?_C++_File_Pgm - Fatal编程技术网

C++ C++;PGM文件在读取中间的每个字符中读取默认值为38?

C++ C++;PGM文件在读取中间的每个字符中读取默认值为38?,c++,file,pgm,C++,File,Pgm,我试图读入一个512x512 pgm文件并将其存储在一个2d数组中。它打印出0-255之间的值,直到35835个无符号字符,然后只打印出其他字符的“38”。奇怪的是,当我试着用前几行字符(像素)制作一个单独的pgm文件时,将它开始只打印出38个字符的点与字符数进行比较,代码并没有开始只打印出38个字符,直到它达到实际字符数的两倍。片段如下: int arr[512][512]; //temp hard coded in if (data.is_open()) { //test to se

我试图读入一个512x512 pgm文件并将其存储在一个2d数组中。它打印出0-255之间的值,直到35835个无符号字符,然后只打印出其他字符的“38”。奇怪的是,当我试着用前几行字符(像素)制作一个单独的pgm文件时,将它开始只打印出38个字符的点与字符数进行比较,代码并没有开始只打印出38个字符,直到它达到实际字符数的两倍。片段如下:

int arr[512][512]; //temp hard coded in
if (data.is_open()) {
    //test to see what gets printed out
    //first 2 to get out the version and comment
    getline(data, line);
    getline(data, line); //get the size of the pgm
    ss << data.rdbuf();
    ss >> numcols >> numrows;
    cout << numcols << " cols " << numrows << " rows \n";
    getline(data, line);
    //get rid of max
    //now get the actual pixels
    for (row = 0; row < numrows; row++) {
        for (col = 0; col < numcols; col++) {
            unsigned char pix;
            ss >> pix;
            arr[row][col] = pix;
            cout << arr[row][col] << " row " << row << " col " << col << "\n";
        }
    }

    data.close();
int-arr[512][512]//温度硬编码输入
if(data.is_open()){
//测试以查看打印出的内容
//前2个获得版本和评论
getline(数据,行);
getline(数据,行);//获取pgm的大小
ss>numcols>>numrows;

如果你想得到帮助,你是否需要发布一个最小的、可复制的示例。在这种情况下,这意味着一个完整的程序(包含
#include
int main
等),而不是一个片段,以及运行它的PGM文件的副本。不要使用基于大堆栈的arrays.PGM文件: