MFC读写txt中的变量

liwenheliwen 2011-12-16 09:31:29
各位大侠帮忙怎么用MFC读取txt中的如下数据并赋予不同的数值,有知道的请指点下,不胜感激,急用啊。
pointd x=-3.000000 y=1.000000 z=0.000000
pointd x=-3.000000 y=0.000000 z=0.000000
pointd x=-2.300000 y=-1.400000 z=0.000000
pointd x=-2.100000 y=-1.300000
...全文
110 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
liwenheliwen 2011-12-20
  • 打赏
  • 举报
回复
结贴吧,没有得到我想要的,
wtbike 2011-12-16
  • 打赏
  • 举报
回复
GetPrivateProfileInt
GetPrivateProfileString
罗平 2011-12-16
  • 打赏
  • 举报
回复
CFile 打开文件
CString 分析字符串
liwenheliwen 2011-12-16
  • 打赏
  • 举报
回复
我说具体点就是把
pointd x=-3.000000 y=1.000000 z=0.000000
pointd x=-3.000000 y=0.000000 z=0.000000
pointd x=-2.300000 y=-1.400000 z=0.000000
pointd x=-2.100000 y=-1.300000

中的数据用另外一个文件中的数据自动替换,而不是读取后手动书写替换再另存。
liwenheliwen 2011-12-16
  • 打赏
  • 举报
回复
各位我的题目是MFC编程,不是win32控制台啊,
FILE *fp;
float xx,yy,zz;
char *name
fp=fopen( name, "r");
if (fp==NULL)
{
printf(" Impossible d'ouvrir le fichier %s\n", name);
return maScene;
}
fscanf(fp, "\tpointd x=%f y=%f z=%f\n", &xx, &yy, &zz);

或者是如下的代码,这两中思路那个可行各位帮忙改写下或者给我给点类似代码,QQ是654806534,谢谢
char *pFileName="C:\\test.txt";
CStdioFile myFile;
CFileException fileException;
if (!myFile.Open(pFileName,CFile::typeText|CFile::modeReadWrite),&fileException)
{
myFile.SeekToBegin();
CString str1;
myFile.ReadString(str1);
CString str2;
myFile.ReadString(str2);
m_plane.Format("%3d",str1);
//AfxMessageBox(str1+str2);
}
else
{
TRACE("Can not open file%s,error=%u\n",pFileName,fileException.m_cause);
}
myFile.Close();
shiyunqiang 2011-12-16
  • 打赏
  • 举报
回复

CString FileExt;
FileExt=((CString)lpszPathName).Right(((CString)lpszPathName).GetLength()-((CString)lpszPathName).ReverseFind('.')-1);


这个是获取扩展名的,你可以改一下。
gradual 2011-12-16
  • 打赏
  • 举报
回复
CStdioFile
ReadString
shiyunqiang 2011-12-16
  • 打赏
  • 举报
回复
判断“=”,只取“=”右边的字符就好了。
振翅高飞 2011-12-16
  • 打赏
  • 举报
回复
方法有很多吧,用CFile没问题,用C的输入输出流函数fopen(),sscanf()函数也没问题。
shen_wei 2011-12-16
  • 打赏
  • 举报
回复
CFile file(_T("1.txt"),CFile::modeRead);
CString str;
file.Read(str,file.GetLength());
file.Close();

下面就是分析Str字符串了。。。

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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