65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <memory.h>
#include <fstream>
using namespace std;
int main()
{
ifstream incth;
incth.open("D:\\text.txt",ios::in);
if(!incth)
{
cerr <<"Error!Cannot open file!" <<endl;
exit(1);
}
char Num[20];
memset(Num,0,20);
cin>>Num; //Num就是我要输入的一个字符串,和从文件中读取的字符串进行比较。
cout <<endl <<"查询结果:" <<endl;
char ch,S[20],total=0;
memset(S,0,20);
while(incth.get(ch))
{
if(total <=6) S[total]=ch;
total++;
}
incth.close();
incth.open("D:\\text.txt",ios::in);
if(!incth)
{
cerr <<"Error!Cannot open file!" <<endl;
exit(1);
}
cout <<endl;
if(strcmp(S,Num)==0)
{
while(incth.get(ch))
cout <<ch;
}
incth.close();
if(strcmp(S,Num)!=0)
cout <<"不存在该项信息,请核对后再查询,O(∩_∩)O谢谢使用!" <<endl;
cout <<endl;
//system("pause");
}