Debugging 当我接受输入时,调试断言错误。“有什么问题吗?”;删除“;?
当我输入两个元素时,我就出现了调试断言错误。在获取7-8个条目后,程序向我提供了访问读取或有时写入违规错误,但在我删除动态数组后,它显示在获取前两个输入后调试断言失败,并出现故障。有没有办法解决这个问题?我在这里只抄我的航空班。我也有类似的火、土和水课程 错误为块类型有效(pHead->nBlockUse) 其他人也问了这个问题,但我无法找出我的程序错误。如蒙惠顾,不胜感激Debugging 当我接受输入时,调试断言错误。“有什么问题吗?”;删除“;?,debugging,runtime-error,Debugging,Runtime Error,当我输入两个元素时,我就出现了调试断言错误。在获取7-8个条目后,程序向我提供了访问读取或有时写入违规错误,但在我删除动态数组后,它显示在获取前两个输入后调试断言失败,并出现故障。有没有办法解决这个问题?我在这里只抄我的航空班。我也有类似的火、土和水课程 错误为块类型有效(pHead->nBlockUse) 其他人也问了这个问题,但我无法找出我的程序错误。如蒙惠顾,不胜感激 #ifndef AIR_H #define AIR_H #include <iostream> #includ
#ifndef AIR_H
#define AIR_H
#include <iostream>
#include <string>
#include "element.h"
using namespace std;
class Air :public Element
{
public:
string air;
string Elements [2];
int i;
string *elements;
public:
Air(string n): Element (n)
{
air = n;
i=-1;
elements = new string[2];
}
void alreadyExists (string a)
{
int lineCount = 0;
ifstream read;
read.open ("Air.txt", ios::in | ios::app);
while(!read.eof())
{
string x;
read>>x;
lineCount++;
}
lineCount--;
read.close();
read.open("Air.txt", ios::in|ios::app);
for(int i = 0; i < lineCount; i++)
{
read>>elements[i];
}
bool Found = false;
for(int i = 0; i < lineCount; i++) {
if(a == elements[i])
{
Found = true;
break;
}
}
if(!Found)
{
write2file (a);
}
}
void write2file (string air)
{
ofstream write;
write.open ("Air.txt", ios::out|ios::app);
{
write<<air<<endl;
}
}
void DisplayA ()
{
/*for(int i=0; i<2; i++)//( to read through the arrays )
{
cout<<Elements[i]<<endl;
}*/
ifstream read ("Air.txt", ios::in|ios::app);
int i=0;
while (read >> Elements[i])
{
cout<<Elements[i]<<endl;
}
}
Air operator+(Air & air)
{
Air newElement ("NULL");
if (this->air == "Air"||this->air=="air"&& air.air == "Air"||air.air=="air")
{
newElement.air = "Pressure";
cout<<"Yay!! You've made: "<<newElement.air<<endl;
alreadyExists (newElement.air);
//PushA (newElement.air);
//write2file (newElement.air);
return newElement;
}
else if ((this->air == "Air"||this->air == "air") && (air.air == "Pressure"||air.air=="pressure"))/* || ((this->air == "Pressure"||this->air=="pressure") && ( air.air == "Air"||air.air=="air")))*/
{
newElement.air = "Atmosphere";
cout<<"Wuhooo!! You've made: "<<newElement.air<<endl;
alreadyExists (newElement.air);
//PushA (newElement.air);
//write2file (newElement.air);
return newElement;
}
else return newElement;
}//pressure, atmosphere
~ Air ()
{
delete []elements;
}
};
#endif
\ifndef AIR\u H
#定义空气湿度
#包括
#包括
#包括“element.h”
使用名称空间std;
类别空气:公共元素
{
公众:
串空气;
字符串元素[2];
int i;
字符串*元素;
公众:
空气(串n):元素(n)
{
空气=n;
i=-1;
元素=新字符串[2];
}
void alreadyExists(字符串a)
{
int lineCount=0;
ifstream读取;
read.open(“Air.txt”,ios::in | ios::app);
而(!read.eof())
{
字符串x;
阅读>>x;
lineCount++;
}
行数--;
read.close();
read.open(“Air.txt”,ios::in | ios::app);
对于(int i=0;i>元素[i];
}
bool-Found=false;
对于(int i=0;i
据我所知,你错过了元素的虚拟解构器。
尝试以下方法:
virtual ~Element() {}
类内元素。
请同时发布元素类
祝你好运
virtual ~Element() {}