读取Test.txt文件内容:
<M:张三/D:21/J:3000/H:2100/E:98989898/-->
#include <iostream>
using namespace std;
char tt[100];
//字符串的截取函数
void GetChar (const char* buf,char* begin,char* end)
{
char* temp = new char[1000];
strcpy(temp,buf);//拷贝给temp
while(*temp != NULL)
{
if(*temp == *begin)
{
char* bt = temp;
while(*bt != NULL)
{
if(*bt == *end)
{
temp++;
temp++;
*bt = '\0';
strcpy(tt,temp);
}
else
{
bt++;
}
}
}
else
{
temp++;
}
}
}
//#include <stdio.h>
void main()
{
FILE* pFile = NULL;
pFile = fopen("Test.txt","r");
char buf[100];
memset(buf,0,100);
fread(buf,1,100,pFile);
cout<<"读取当前硬盘上的数据是:"<<buf<<endl;
GetChar(buf,"M","/");
cout<<"名字是:"<<tt<<endl;
GetChar(buf,"D","/");
cout<<"等级是:"<<tt<<endl;
GetChar(buf,"J","/");
cout<<"金钱是:"<<tt<<endl;
GetChar(buf,"H","/");
cout<<"HP是:"<<tt<<endl;
GetChar(buf,"E","/");
cout<<"经验是:"<<tt<<endl;
cout<<"读取硬盘数据完毕"<<endl;
fclose(pFile);
}