crt检测到应用程序在堆缓冲区结束后写入了内存 [英] crt detected that the application wrote to memory after end of heap buffer

查看:931
本文介绍了crt检测到应用程序在堆缓冲区结束后写入了内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的命令行C ++程序,但是遇到了堆损坏错误.以下是我程序的代码.
任何人都可以帮我吗??????????

I was writing a simple commandline C++ program , but I am running into Heap Corruption errors . The following is my program''s code.
please can anyone help me ??????????

void evenValue()
{

	cout<<endl<<"                  * * * WELCOME * * *"<<endl<<endl;
	cout<<"How many elements do you want to enter to queue: ";

	int length1,i,element1; //=====================  // My queue 
	queues q1;
	cin>>length1;
	cout<<"Enter "<<length1<<" elements: ";
	for(i=0;i<length1;i++)
	{
		cin>>element1;
		q1.insert_rear(element1);
	}
	//==========================================================================================================
int element;
int count = 0;
   		for(int ptr=q1.front;ptr<=q1.rear;ptr++)
			{	
				if(q1.queue[ptr]%2==0)
					count++;
	        }
	      //=====================  // My stack 
//	int length,element;
  //  cout<<"Enter many item do you want to fill the stack"<<endl;
    //cin>> length;
	
    My_Stack s1(count); 
  //  int * x;
  //  x = new int [count];

   cout << "Pushing elements " << endl;
    for (int i = 0; i < count; i++)
	 {  
		 for(int ptr=0; ptr < q1.Size();ptr++)
			{	
				if(q1.queue[ptr]%2==0)
				{
				element = q1.queue[ptr];
				s1.push(element);
			//	cout<<s.items[ptr]<<"    ";
				}
				}
	}
    	s1.display(s1);}

推荐答案

很难说,却看不到您的类队列和My_Stack.但是只是猜测而已:

a)计数设置为队列中偶数元素的数量.

b)然后确定堆栈的大小以容纳此数量的元素.

c)在队列元素的第二个循环中,您使用另一种迭代,即0 --- ql.Size(),而不是ql.front ... ql.read-是故意的

d)您将count * count元素压入堆栈,该堆栈的大小仅用于容纳count元素-这是故意的吗?

最后一条语句看起来有些多余:sl.display(sl).它应该是sl.display()display (sl).

我希望这些观察之一能使您重回正轨.
Hard to tell without seeing your classes queues and My_Stack. But just from guessing:

a) count is set to the number of even elements in your queue.

b) then your stack is dimensioned to hold this count of elements.

c) in the second loop over the queue elements you use a different kind of iteration, namely 0 --- ql.Size(), instead of ql.front ... ql.read -- was that intentional

d) you push count*count elements onto your stack that was dimensioned for holding only count elements -- was that intentional?

The last statement looks somewhat redundant: sl.display(sl). Either it should be sl.display() or display (sl).

I hope that one of these observations gets you back on track.


这篇关于crt检测到应用程序在堆缓冲区结束后写入了内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆