未处理的异常,访问冲突 [英] Unhandled Exception, Access Violation

查看:69
本文介绍了未处理的异常,访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当程序使用编码中的数据时,程序运行完美。

但是当我尝试从txt文件导入时他出了问题。

代码从txt导入工作



i得到消息错误

Tanks.exe中0x014621fa处的未处理异常:0xC0000005:访问冲突读取位置0xfeeefeee。



它指向行

  void  Graph :: addEdge( int  u, int  v){
A [u- 1 ] [v- 1 ] = 1 ;
此行 - > A [v- 1 ] [u- 1 ] = 1 ;
}





乐趣得到1和2.

真的不知道问题为什么



回复谢尔盖 -

是的当然是我在这里添加的评论。



做了几次调试和同样的错误。

如果我把数据放在我的代码中,比如

g.addEdge(1,2); g.addEdge(1,3);

g.addEdge(2,3); g.addEdge(2,4);

g.addEdge(3,4); g.addEdge(4,5);



它完美无缺。但是当我在txt的导入行之间添加g.addedge并显示问题。

解决方案

在你的函数中写一些检查代码,如:



  void  Graph :: addEdge( int  u, int  v){
ASSERT((u> 0)&&(v> 0)); // !!!! 0有效(我的提示)
ASSERT((你的[u- 1 ] [v- 1 ] = 1 ;
}





写一些错误检查和测试代码是好的风格,总是还清。; - )


the program run perfect when the program use the data from the coding.
but when i try to import from txt file he make a problems.
the code of the import from txt is working

i got message error
Unhandled exception at 0x014621fa in Tanks.exe: 0xC0000005: Access violation reading location 0xfeeefeee.

and it point to line

void Graph::addEdge(int u, int v) {
    A[u-1][v-1] =1; 
THIS LINE->	A[v-1][u-1] = 1;
}



the fun get 1 and 2.
really dont know why the problem

reply to Sergey-
yeah ofcourse its just comment that i added here.

did few times debug and same error.
if i put data in my code like
g.addEdge(1, 2); g.addEdge(1, 3);
g.addEdge(2, 3); g.addEdge(2, 4);
g.addEdge(3, 4); g.addEdge(4 ,5);

it works perfect. but when i add g.addedge between the lines of import from txt and show the problem.

解决方案

write some check code in your function like:

void Graph::addEdge(int u, int v) {
  ASSERT( (u>0) && (v>0) ); //!!!! 0 is valid (my tip)
  ASSERT( (u    A[u-1][v-1] =1; 
}



writing some error check and test code is good style and always paying off. ;-)


这篇关于未处理的异常,访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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