把这个文件放在哪里呢——一个非常非常小的问题,但是折磨了小弟好久了,小弟快没有分了,各位高手帮帮忙,先谢谢了

laohubinbin 2004-04-11 06:02:10
小弟的程序(不是发行版本)中需要读取一个外部的txt文件(相当于一个库):
dicomInformationFile.Open("dicom_information_file.txt",CFile::modeRead|CFile::typeText)
那么,这个dicom_information_file.txt应该放到哪里呢?
...全文
68 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
laohubinbin 2004-04-11
  • 打赏
  • 举报
回复
运行时还是会出现对话框提示“找不到dicom_information_file.txt”
code8238 2004-04-11
  • 打赏
  • 举报
回复
if(dicomInformationFile.Open("dicom_information_file.txt",CFile::modeRead|CFile::typeText)==0) 《-读取
{
AfxMessageBox("找不到dicom_information_file.txt"); 《-检测是否打开
return NULL;
}

Open函数返回为0不一定是因为找不到文件,建议这么改试试行不行

if(dicomInformationFile.Open("dicom_information_file.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeRead|CFile::typeText)==0) 《-读取
{
AfxMessageBox("找不到dicom_information_file.txt"); 《-检测是否打开
return NULL;
}
laohubinbin 2004-04-11
  • 打赏
  • 举报
回复
struct dicomdata* CDicom::ReadDicomData(LPCTSTR lpszPathName)
{
struct dicomdata *ptmp,*p1, *p2;
ptmp=new struct dicomdata;
CStdioFile dicomInformationFile; 《-定义
CString stringGroup;
CString stringElement;
CString stringInformation;

//导出路径名称所指引的文件
if(m_commenFile.Open(lpszPathName,CFile::modeRead|CFile::shareDenyNone,NULL)==0)
{
AfxMessageBox("dicom文件找不到!");
return NULL;
}

//找到文件的头位置,读取4*sizeof(byte)长的数据
m_commenFile.SeekToBegin();
ptmp->lWhere=m_commenFile.GetPosition();
m_commenFile.Read(tx,4*sizeof(byte));

//判断是否有DICM字符
if (tx[0]!='D'||tx[1]!='I'||tx[2]!='C'||tx[3]!='M')
{
//若没有DICM字符,后移128个字节,再读取4*sizeof(byte)长的数据
m_commenFile.Seek(128,CFile::begin);
ptmp->lWhere=m_commenFile.GetPosition();
m_commenFile.Read(tx,4*sizeof(byte));

//判断是否有DICM字符
if (tx[0]!='D'||tx[1]!='I'||tx[2]!='C'||tx[3]!='M')
{
//若没有DICM字符,重新回到文件头位置,读取标签位置号码
m_commenFile.SeekToBegin();
ptmp->lGroup=read16(m_commenFile,m_littleEndian);
ptmp->lElement=read16(m_commenFile,m_littleEndian);

//判断有无关键信息项
if ((ptmp->lGroup!=0x0000)&&(ptmp->lGroup!=0x0002)&&(ptmp->lGroup!=0x0004)&&(ptmp->lGroup!=0x0008))
exit(0);

//重新回到文件头位置
m_commenFile.SeekToBegin();
}
}
//删除临时指针
delete ptmp;

p1=p2=new struct dicomdata;
m_quantity=0;
pHead=NULL;

//变量初始化
m_bytesPerPixel=1;
p1->strInfo="";
p1->strDataInformation="";

m_timetoQuit=false;
while (!m_timetoQuit)
{
t=unknown;
//取得数据头位置、标签号码
p1->lWhere=m_commenFile.GetPosition();
p1->lGroup=read16(m_commenFile,m_littleEndian);
p1->lElement=read16(m_commenFile,m_littleEndian);
if (p1->lGroup==0x0002)
{
m_dummy=read16(m_commenFile,m_littleEndian);
p1->lE_len=read16(m_commenFile,m_littleEndian);
if (p1->lElement==0x0001)
{
m_dummy=read32(m_commenFile,m_littleEndian);
m_dummy=read16(m_commenFile,m_littleEndian);
p1->lE_len=0;
}
}
else
{
p1->lE_len=read32(m_commenFile,m_littleEndian);
m_remaining=p1->lE_len;
}


//由标签号码判断信息项名称
p1->strInfo="unknown";

BOOL notFindedInformationFlag=TRUE;
BOOL notReachEnd=TRUE;
while (notFindedInformationFlag&¬ReachEnd)
{
if(dicomInformationFile.Open("dicom_information_file.txt",CFile::modeRead|CFile::typeText)==0) 《-读取
{
AfxMessageBox("找不到dicom_information_file.txt"); 《-检测是否打开
return NULL;
}
notReachEnd=dicomInformationFile.ReadString(stringGroup);
dicomInformationFile.ReadString(stringElement);
dicomInformationFile.ReadString(stringInformation);
CString tmpString1;
CString tmpString2;
tmpString1.Format("%.4x",p1->lGroup);
tmpString2.Format("%.4x",p1->lElement);
if (stringGroup==tmpString1&&stringElement==tmpString2)
{
p1->strInfo=stringInformation;
notFindedInformationFlag=FALSE;
}
}
……
……
运行就会出现对话框提示“找不到dicom_information_file.txt”
麻烦了
谢谢
gwcui 2004-04-11
  • 打赏
  • 举报
回复
也许是程序别的地方的错呀
code8238 2004-04-11
  • 打赏
  • 举报
回复
那就不是文件放没放错地方的问题了,把代码贴出来看看。
laohubinbin 2004-04-11
  • 打赏
  • 举报
回复
dicomInformationFile.Open("dicom_information_file.txt",CFile::modeRead|CFile::typeText)
就可以了吗?

小弟试过了呀
打不开呀
code8238 2004-04-11
  • 打赏
  • 举报
回复
如果是在VC下运行,把它放到DEBUG文件夹外
如果是直接运行DEBUG里的EXE文件,把它放到和这个EXE同样的目录里

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧