我在VC++程序中要实现向文件中写数据,然后在从文件中读出数据,然后通过调用MATLAB函数处理这些数据,每次在编译能通过,但运行时却出现错误提示 "0x10218253"指令引用的"0xcccccccccccc"内存。该内存不能为”read"
主程序中调用ReadAnsysResult("E:\\thesis\\program\\matrix001.txt");
函数为void CThesis001Dlg::ReadAnsysResult(CString FileName)
{
}
由于程序太多、太复杂 所以代码省略 我查了参数传递 和函数代码都没问题 而且ReadAnsysResult(CString FileName)我在其他工程中调用也是没问题的,希望大家帮帮忙
主程序中调用ReadAnsysResult("E:\\thesis\\program\\matrix001.txt");
函数为void CThesis001Dlg::ReadAnsysResult(CString FileName)
{
}
由于程序太多、太复杂 所以代码省略 我查了参数传递 和函数代码都没问题 而且ReadAnsysResult(CString FileName)我在其他工程中调用也是没问题的,希望大家帮帮忙
解决方案 »
- 谁有<<Visual C++开发经验技巧宝典>>的源码,给我一份好吗?谢谢
- FieldsPtr是什么类型?用它时需要声明什么头文件?
- 请教这个是什么错误?
- 问几个问题:笔试的时候不会的
- 因为我的一些窗口打开前需要进行数据表的选择连接,比较慢,我想在打开时在状态栏里显示进度条
- 左移的操作数必需是整型么?
- 谁能给我讲讲CArchive和CFile的用法,比如怎样存储几个不同类型的数据,并且取出来
- 【求助】如何能在同一个excel表格中通过按钮不断插入数据
- 写一个函数,来实现对BMP位图的RGB的buffer进行像素改变,就是画V型线。
- 编程实现windows系统下禁用可移动大容量存储设备以及大容量设备只读
- 在VS2005底下的win32控制台应用程序下编写一个鼠标程序,咋样才能点一下鼠标让在鼠标点的位置出现一个闪动的光标。谢谢啦,急。
- 关于反复读串口的问题
#include <errno.h>#include "stdafx.h"
#include "thesis001.h"
#include "thesis001Dlg.h"
#include <string.h>
#include <direct.h>
#include "engine.h"
#include "math.h"
#include <fstream.h>
#include <iostream.h>
#include <stdio.h> 主程序调用
void CThesis001Dlg::CacuFit(individual *critter)
{
for (int Index=0;Index<popsize;Index++)
{
WriteAnsysTry("E:\\thesis\\program\\beamtry01.txt",AllPara[Index].H);
AnsysProcess();
ReadAnsysResult("E:\\thesis\\program\\matrix001.txt");
MatlabProcess(AllPara[Index].I,AllPara[Index].K);
critter[Index].Fz=AllPara[Index].Fz_Optimize;
critter[Index].Qp=AllPara[Index].Qp_Optimize;
critter[Index].Ts=AllPara[Index].Ts_Optimize;
//确定目标函数值
if (AllPara[Index].Fz_Optimize==0)
exit(-1);
if (ValueFlag==1)
{
critter[Index].fitness=p_Qp*AllPara[Index].Qp_Optimize+p_Ts*AllPara[Index].Ts_Optimize+p_Fz/AllPara[Index].Fz_Optimize;if (critter[Index].fitness!=0)
critter[Index].fitness=1/critter[Index].fitness;
}
else
critter[Index].fitness=0;
}
}函数定义如下:
void CThesis001Dlg::ReadAnsysResult(CString FileName)
{
fstream infile;
infile.open(FileName,ios::in);
if(!infile) //打开文件失败、中断
{
MessageBox("File doesn't exist!");
abort();
}
char buffers[256];
//根据特征字符串切分出两个矩阵StiffStr,MassStr 的字符串
CString strS="***** STIFFNESS MATRIX *****";
CString strM="***** MASS MATRIX *****";
CString strO="*** PROBLEM STATISTICS";
CString a;
CString StiffStr,MassStr;
BOOLEAN flagS,flagM;
int pos=0,startpos=0,endpos=0,midpos=0;
do
{
infile.getline(buffers,sizeof(buffers));
a=(CString)buffers;
startpos=a.Find(strS,0);
midpos=a.Find(strM,0);
endpos=a.Find(strO,0);
if (startpos!=-1) flagS=TRUE;
if (midpos!=-1)
{ flagS=FALSE;
flagM=TRUE;
}
if (endpos!=-1) flagM=FALSE;
if (flagS==TRUE) StiffStr+=a;
if (flagM==TRUE) MassStr+=a;
}
while (!infile.eof());
infile.close();
//根据特征字符串(UY,ROW)切分出矩阵StiffStr,MassStr 的数值字符串
//分别存入字符串数组aStiff,aMass 中
int sp,length;
CString temp;
CStringArray aStiff,aMass;
//StiffStr
a=StiffStr;
do{
sp=a.Find("UY",0);
sp=a.Delete (0,sp+5);
sp=a.Find("ROW",0);
if (sp==-1) break;
temp=a;
length=temp.GetLength();
sp=temp.Delete (sp-1,length-sp+1);
temp.TrimLeft ();
aStiff.Add(temp);
}while (!temp.IsEmpty ());
a.TrimRight();
a.TrimLeft ();
aStiff.Add(a);
//MassStr
a=MassStr;
do{
sp=a.Find("UY",0);
sp=a.Delete (0,sp+5);
sp=a.Find("ROW",0);
if (sp==-1) break;
temp=a;
length=temp.GetLength();
sp=temp.Delete (sp-1,length-sp+1);
temp.TrimLeft ();
aMass.Add(temp);
}while (!temp.IsEmpty ());
a.TrimRight();
a.TrimLeft();
aMass.Add(a);
//读取aStiff 中的字符串 转化成double 型数组
//存放在ArrayStiff 中
int ROW=(aStiff.GetAt(0).GetLength ()+4)/20;
int vitual=(aStiff.GetAt(0).GetLength ()+4)%20;
if (vitual>10) ROW+=1;
int COL=aStiff.GetSize();
double vv;
CString valStr;
//double *ArrayStiff;
//double *ArrayMass;
ArrayStiff = new double[ROW*COL];
Length_Stiff=ROW*COL;
for (int j=0;j<COL;j++)
{
temp=aStiff.GetAt(j);
for (int i=0;i<ROW;i++)
{
if (temp.GetLength ()>18)
{
valStr=temp.Left(18);
sp=temp.Delete (0,17);
temp.TrimLeft ();
}
else
{
temp.TrimLeft ();
valStr=temp;
}
valStr.TrimRight();
valStr=valStr.Right(15);
valStr.TrimLeft();
vv=atof(valStr);
ArrayStiff[i+j*ROW]=vv;
}
}
//读取aMass 中的字符串 转化成double 型数组
//存放在ArrayMass 中
ROW=(aMass.GetAt(0).GetLength ()+4)/20;
vitual=(aMass.GetAt(0).GetLength ()+4)%20;
if (vitual>10) ROW+=1;
COL=aMass.GetSize();
//double *ArrayMass;
ArrayMass = new double[ROW*COL];
Length_Mass=ROW*COL;
for (j=0;j<COL;j++)
{
temp=aMass.GetAt(j);
for (int i=0;i<ROW;i++)
{
if (temp.GetLength ()>18)
{
valStr=temp.Left(18);
sp=temp.Delete (0,17);
temp.TrimLeft ();
}
else
{
temp.TrimLeft ();
valStr=temp;
}
valStr.TrimRight();
valStr=valStr.Right(15);
valStr.TrimLeft();
vv=atof(valStr);
ArrayMass[i+j*ROW]=vv;
}
}
}
而且E:\\thesis\\program\\matrix001.txt文件 已经产生 请大家帮看看错误出在哪
http://blog.csdn.net/qiqi5521/archive/2008/03/06/2154074.aspx这个工具不光可以检测内存泄漏和访问非法访问,还可以自动的发现未初始化指针的使用。
是国外的一个软件,下载地址:
http://download.csdn.net/source/297822
http://download.csdn.net/source/297824