#include
#include
#include
#include
using namespace std;
int read(char *ch){
cout<
ofstream outfile;
outfile.open("test.txt",ios::out|ios::app);
if(!outfile){
cout
}
char*endptr,*str,*mname;
int i,k,Dose;
for(i=0;ch[i]'9';i++)
mname[i]=ch[i];
mname[i]='\0';
for(k=0;ch[i]>='0'&&ch[i]<='9';i++,k++){
str[k]=ch[i];
}
Dose=strtol(str,&endptr,10);
outfile<<mname<<Dose<<endl;
outfile.close();
return i;
}
void Handle(char ch[]){
char filen[256];
strcpy(filen,ch);
ifstream infile1;
infile1.open(filen,ios::in);
while(!infile1)
{
cout<<"不能打开输入文件夹:"<
cout
cin>>filen;
infile1.clear();
infile1.open(filen,ios::in);
}
infile1.unsetf(ios::skipws);
char buf[10000];
int cir=0,bt=0;
while(infile1.getline(buf,10000)) //一行一行进行读取文件一
{
char*begin=buf;
do{
bt=read(begin);
if(begin+bt+3!=NULL){
begin+bt+3;
cir=1;
}
else cir=0;
}while(cir=1);
}
infile1.close();
}
int main(){
char testfilename[256];
cout<<"请输入原始文件: ";
cin>>testfilename;
Handle(testfilename);
}
其中测试文件:1.txt内容为
党参1克,当归10克
连翘5克
党参和1分别存储在char*mname和char*str中,后将char*str转换成int值