不难啊,只是麻烦。用fscanf就行了
解决方案 »
- 在指定时间段内执行指定次数?高手进,高性能考虑。。。
- 菜鸟求助:写一个DLL,实现对SQL数据库中表项的增加与删除!
- CreateNamedPipe产生的HANDLE在DisconnectNamedPipe后是否需要使用CloseHandle关掉?
- 如何在备份oracle中的表?
- ADO连接
- 帮我看看下面的代码有什么错误?熟悉低级音频api的请进
- 波波进来领分!
- 学热能工程的同志请进!
- Who help me? I want to kill Bill Gates.
- CTreeCtrl的展开和收缩
- 老问重提,请问如何调用蓝屏,不是自己画的,就像调用一种系统服务一样,可以吗,听说是藏在一个未公开的API中?
- 请高手指点关于LDAP API的使用,谢谢!!!
谢谢
要不你就用CStdioFile,CString来处理也行啊。
#include <iostream>
#include <fstream>using namespace std;int main()
{
ifstream ifile("d:\\test.dat",ios::in | ios::out);
if(!ifile.fail())
{
char buf[256];
char *start;
char *name;
char *value;
cout<<"name\tvalue"<<endl;
cout<<"----\t----"<<endl;
while(!ifile.eof())
{
ifile.getline(buf,256);
start=buf;
while(1)
{
name=start;
if(name==0 || *name=='\0')
break;
value=strchr(name,'#');
if(value==0)
break;
*value='\0';
value++;
start=strchr(value,',');
if(start==0)
break;
else
{
*start='\0';
start++;
cout<<name<<"\t"<<value<<endl;
}
}
} ifile.close();
}
return 0;
}
if ((fSource = fopen(m_files, "r")) == NULL)
{
AfxMessageBox("Error! Can't open the Source Data File.");
}
char buf[1024];
while (fgets(buf,1024,fSource) != NULL)
{
……
}
可以用sscanf()函数对buf的内容进行转换。
也可以将buf的内容赋值给一个CString变量,用find(),insert(),等等对字符串操作。具体使用可以看msdn。