读书人

运行时出现的有关问题!待,多谢!

发布时间: 2012-04-08 14:38:30 作者: rapoo

运行时出现的问题!在线等待,谢谢!!
--Line.h----------------
#include <fstream>
using namespace std;

struct TYPE_DXF
{
float x1,x2,y1,y2;
};

class Line
{
public:
Line(char* filepath, TYPE_DXF coordinate);
~Line();
void Write();
protected:
TYPE_DXF dxf;
ofstream stream;
};


-----Line.cpp-------
#include "Link.h "
Line::Line(char* filepath, TYPE_DXF coordinate)
{
dxf.x1 = coordinate.x1;
dxf.x2 = coordinate.x2;
dxf.y1 = coordinate.y1;
dxf.y2 = coordinate.y2;

stream.open(filepath);
if(stream.fail())
{
cout < < "error opening file " < < filepath < <endl;
exit(0);
}
}

Line::~Line()
{
delete stream;
}

void Line::Write()
{
stream < < "0\n "
< < "SECTION\n "
< < "2\n "
< < "ENTITIES\n "
< < "0\n "
< < "LINE\n "
< < "8\n "
< < "LINE\n "
< < "10\n "
< < dxf.x1 < < "\n "
< < "11\n "
< < dxf.x2 < < "\n "
< < "20\n "
< < dxf.y1 < < "\n "
< < "21\n "
< < dxf.y2 < < "\n "
< < "0\n "
< < "ENDSEC\n "
< < "0\n "
< < "EOF "
< < endl;
}

---------DrawLine.cpp--------
#include <iostream.h>
#include "Line.h "

void main()
{
char filepath[100];
TYPE_DXF coordinate;

cout < < "请输入直线的相关数据:\n "
< < "x1: "
< <endl;
cin > > coordinate.x1;
cout < < "y1: ";
cin > > coordinate.y1;
cout < < "x2 ";
cin > > coordinate.x2;
cout < < "y2 ";
cin > > coordinate.y2;

cout < < "输入所要保存的文件名(dxf类型): ";
cin > > filepath;

Line line(filepath, coordinate);
line.Write();
}
不知道为什么在编译连接时都没错,就是在运行时出现错误

Debug Assertion Failed!

Program:F:\a\Debug\DrawLine.exe
File:dbgheap.c
Line:1044

Expression: _CrtIsValidHeapPointer(pUserData)

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)

终止A 重试R 忽略I

这个是什么原因

------解决方案--------------------


/*********** line.h ************/
#include <fstream>
using namespace std;

struct TYPE_DXF
{
float x1,x2,y1,y2;
};

class Line
{
public:
Line(char* filepath, TYPE_DXF coordinate);
~Line();
void Write();
protected:
TYPE_DXF dxf;
ofstream stream;
};

/*********** line.cpp ************/
#include <iostream>
#include "line.h "
using namespace std;

Line::Line(char* filepath, TYPE_DXF coordinate)
{
dxf.x1 = coordinate.x1;
dxf.x2 = coordinate.x2;
dxf.y1 = coordinate.y1;
dxf.y2 = coordinate.y2;

stream.open(filepath);
if(stream.fail())
{
cout < < "error opening file " < < filepath < <endl;
exit(0);
}
}

Line::~Line()
{
delete stream;
}

void Line::Write()
{
stream < < "0\n "
< < "SECTION\n "
< < "2\n "
< < "ENTITIES\n "
< < "0\n "
< < "LINE\n "
< < "8\n "
< < "LINE\n "
< < "10\n "
< < dxf.x1 < < "\n "
< < "11\n "
< < dxf.x2 < < "\n "
< < "20\n "
< < dxf.y1 < < "\n "
< < "21\n "
< < dxf.y2 < < "\n "
< < "0\n "
< < "ENDSEC\n "
< < "0\n "
< < "EOF "
< < endl;
}

/*********** DrawLine.cpp ************/
#include <iostream.h>
#include "Line.h "

int main()
{
char filepath[100];
TYPE_DXF coordinate;

cout < < "ÇëÊäÈëÖ±ÏßµÄÏà¹ØÊý¾Ý£º\n "
< < "x1: "
< <endl;
cin > > coordinate.x1;
cout < < "y1: ";
cin > > coordinate.y1;
cout < < "x2 ";
cin > > coordinate.x2;
cout < < "y2 ";
cin > > coordinate.y2;

cout < < "ÊäÈëËùÒª±£´æµÄÎļþÃû(dxfÀàÐÍ): ";
cin > > filepath;

Line line(filepath, coordinate);
line.Write();

return 0;
}

已经编译连接通过,可以正常运行了。

读书人网 >C++

热点推荐