错误:“ C6262:函数使用堆栈的'1600000620'字节:超出/分析:堆栈大小'16384'。请考虑将一些数据移至堆中”

构建代码时,运行没有问题,但是我调试了代码,这生成了一条消息:函数使用栈的'1600000620'字节:超出/分析:stacksize 16384'。

我将声明:int array [2000] [2000]放入int main {}中,因为当int array [2000] [2000]不在int main {}中时,它会产生错误:array不明确。>

#include <iostream> 
#include <fstream> 
#include <sstream> 
using namespace std;

/* Function to sort an array using insertion sort*/
void insertionSort(int arr[],int n)
{
    int i,key,j;
    for (i = 1; i < n; i++){
        key = arr[i];
        j = i - 1;
        /* Move elements of arr[0..i-1],that aregreater than key,to one 
position aheadof their current position */
        while (j >= 0 && arr[j] > key){
            arr[j + 1] = arr[j];
            j = j - 1;
        }
        arr[j + 1] = key;
    }
}

int arr[2000][2000];
int main()
{
    int array[2000][2000];
    int window[9],row = 0,col = 0,numrows = 0,numcols = 0,MAX = 0;
    ifstream infile("phone.jpg");
    stringstream ss;
    string inputLine = "";

    // First line : version
    getline(infile,inputLine);
    if (inputLine.compare("P2") != 0) cerr << "Version error" << endl;
    else cout << "Version : " << inputLine << endl;

    // Continue with a stringstream
    ss << infile.rdbuf();

    // Secondline : size of image
    ss >> numcols >> numrows >> MAX;

    //print total number of rows,columns and maximum intensity of image
    cout << numcols << " columns and " << numrows << " rows" << endl<< 
    "Maximium Intesity "<< MAX <<endl; 

    //Initialize a new array of same size of image with 0
    for (row = 0; row <= numrows; ++row)
    {
        array[row][0] = 0;
    }
    for (col = 0; col <= numcols; ++col) {
        array[0][col] = 0;
    }

    // Following lines : data
    for (row = 1; row <= numrows; ++row)
    {
        for (col = 1; col <= numcols; ++col)
        {
            //original data store in new array
            ss >> array[row][col];
        }
    }

    // Now print the array to see the result
    for (row = 1; row <= numrows; ++row)
    {
        for (col = 1; col <= numcols; ++col)
        {
        //neighbor pixel values are stored in window including this pixel
            window[0] = array[row - 1][col - 1];
            window[1] = array[row - 1][col];
            window[2] = array[row - 1][col + 1];
            window[3] = array[row][col - 1];
            window[4] = array[row][col];
            window[5] = array[row][col + 1];
            window[6] = array[row + 1][col - 1];
            window[7] = array[row + 1][col];
            window[8] = array[row + 1][col + 1];

            //sort window array
            insertionSort(window,9);

            //put the median to the new array 
            arr[row][col] = window[4];
        }
    }

    ofstream outfile;

    //new file open to stroe the output image 
    outfile.open("Medianfilter.pnm");
    outfile << "P2" << endl;
    outfile << numcols << " " << numrows << endl;
    outfile << "255" << endl;

    for (row = 1; row <= numrows; ++row)
    {
        for (col = 1; col <= numcols; ++col)
        {
            //store resultant pixel values to the output file
            outfile << arr[row][col] << " ";
        }
    }

    outfile.close();
    infile.close();
    return 0;
}

我希望该程序可以清除图像,消除图像中的噪点。

esoko 回答:错误:“ C6262:函数使用堆栈的'1600000620'字节:超出/分析:堆栈大小'16384'。请考虑将一些数据移至堆中”

由于使用int array[2000][2000];,因此无法将声明using namespace std;移到全局范围。

using namespace std;语句指示编译器将在命名空间std中找到的所有名称导入全局命名空间,以便您可以直接使用它们(例如string)而不用访问它们通过其名称空间(例如std::string)。

通常不建议这样做,请参阅this question,您会在这里找到一个很好的例子。

自C ++ 11起,标准库名称空间array中有一个名为std的类模板,请参见reference for std::array

这意味着array已经可能在全局范围内具有含义。然后,您尝试声明一个名称为array的变量,并且编译器不再知道array应该引用您声明的变量还是从标准库名称空间导入的类模板。因此出现错误消息。

要解决此问题,请为变量array使用其他名称,或者更好的是,不要使用using namespace std;并使用std::限定对标准库的所有引用。

,

在int main {}解决问题之前,更改变量数组的名称,并将其从int main {}中删除。之所以引起歧义,是因为array是C ++中的一个类,a和之前被声明为整数的代码。因此,将名称数组更改为其他任何名称(如arr1)即可解决该问题。

.select-hidden {
  display: none;
  visibility: hidden;
  padding-right: 10px;
}

.select {
  cursor: pointer;
  display: inline-block;
  position: relative;
  font-size: 16px;
  color: #fff;
  width: 220px;
  height: 40px;
}

.select-styled {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #c0392b;
  padding: 8px 15px;
  -moz-transition: all 0.2s ease-in;
  -o-transition: all 0.2s ease-in;
  -webkit-transition: all 0.2s ease-in;
  transition: all 0.2s ease-in;
}
.select-styled:after {
  content: "";
  width: 0;
  height: 0;
  border: 7px solid transparent;
  border-color: #fff transparent transparent transparent;
  position: absolute;
  top: 16px;
  right: 10px;
}
.select-styled:hover {
  background-color: #b83729;
}
.select-styled:active,.select-styled.active {
  background-color: #ab3326;
}
.select-styled:active:after,.select-styled.active:after {
  top: 9px;
  border-color: transparent transparent #fff transparent;
}

.select-options {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  z-index: 999;
  margin: 0;
  padding: 0;
  list-style: none;
  background-color: #ab3326;
}
.select-options li {
  margin: 0;
  padding: 12px 0;
  text-indent: 15px;
  border-top: 1px solid #962d22;
  -moz-transition: all 0.15s ease-in;
  -o-transition: all 0.15s ease-in;
  -webkit-transition: all 0.15s ease-in;
  transition: all 0.15s ease-in;
}
.select-options li:hover {
  color: #c0392b;
  background: #fff;
}
.select-options li[rel="hide"] {
  display: none;
}
本文链接:https://www.f2er.com/3162774.html

大家都在问