vc++文件内容读入变量问题 比如我有一个DAT文件,里面只有两个个数据12345 54321(用空格隔开),我想把它读取到变量a,b中,之前试过串行化和CFile::Read,但是读入的数据都是分开的(比如把12345的第一个数1读给了a),那怎样才能把12345,54321一整个数字fenbie1读进变量a,b中呢????如果已将“12345 54321”用ReadString读了字符串,可否实现,有没有更好的方法,小弟新学,忘高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 又发了个贴问啊,我帮你写了个程序可以分割的,调试通过,你试试看行不行吧void CSubButtonDlg::OnOK() { CStdioFile file; CString a,b; //存放读出来的字符串 file.Open(_T("c:\\DAT.DAT"), CFile::modeRead); CString strLine(_T("")); int nLineCount = 0; file.ReadString(strLine); int number = atoi(strLine); // "12345" file.Close(); CStringArray dest; while(strLine.Find( " ") != -1) { int k = strLine.Find( " "); dest.Add(strLine.Left(k)); strLine = strLine.Mid(k+1); } dest.Add(strLine); a = dest.GetAt(0); b = dest.GetAt(1);// MessageBox(dest.GetAt(0));// MessageBox(dest.GetAt(1));} 一次读取到buffer中,利用_tcstok()以空格为分隔符来分割 CStdioFile file; //定义文件对象类型为CStdioFilefile.Open("c:\\DAT.DAT", CFile::modeRead);//打开文件,文件索引目录自己设CString str;file.ReadString(str); //读取一行字符串int index=str.Find(' '); //下面都是对字符串操作了CString astr=str.Left(index);CString bstr=str.Right(index);int a=atoi(astr); //包含<stdlib.h>int b=atoi(bstr); 拖拽时弹出模态对话框,程式卡死了 频繁载入与释放资源,程序内存占用不断增大? 招聘Win下应用程序开发工程师(MFC/VC++) 如何在对话框中使用子窗口显示更多的控件? 如何强制删除文件? 如何在VC6中为控件增加事件?如何在VC7中为控件增加属性? 多线程问题 如何实现点击combox的编辑框,显示combox的列表 如何得到internet服务器上文件的时间 宝贝创作室找高手写Vs7、VB 7、Asp.Net、C#的书!(信誉好) VC OLE EXCEL 怎么复制指定区域和黏贴啊。。 VC 串口接收数据的解析
{
CStdioFile file;
CString a,b; //存放读出来的字符串
file.Open(_T("c:\\DAT.DAT"), CFile::modeRead);
CString strLine(_T(""));
int nLineCount = 0;
file.ReadString(strLine);
int number = atoi(strLine); // "12345"
file.Close(); CStringArray dest;
while(strLine.Find( " ") != -1)
{
int k = strLine.Find( " ");
dest.Add(strLine.Left(k));
strLine = strLine.Mid(k+1);
}
dest.Add(strLine);
a = dest.GetAt(0);
b = dest.GetAt(1);
// MessageBox(dest.GetAt(0));
// MessageBox(dest.GetAt(1));}
file.Open("c:\\DAT.DAT", CFile::modeRead);//打开文件,文件索引目录自己设
CString str;
file.ReadString(str); //读取一行字符串
int index=str.Find(' '); //下面都是对字符串操作了
CString astr=str.Left(index);
CString bstr=str.Right(index);
int a=atoi(astr); //包含<stdlib.h>
int b=atoi(bstr);