15--5一下午的结晶,娜氏电子词典。

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
string e[8000],c[8000];   //在函数里要用所以在外声明
int Seareh(int low, int high, string k);
int main()
{
    int i=0,num=0;
    string b;
    ifstream infile("fun.txt",ios::in);
    if(!infile)
    {
        cerr<<" open error!"<<endl;
        exit(1);       //强行关闭
    }
    while(infile>>e[i]>>c[i])
    {
        i++;
        num++;
    }
    infile.close();
    cout<<num<<endl;           //想看一下到底有多少个英语
    do
   {
       cout<<"请输入要查的词(0000结束):";
        cin>>b;
       if (b=="0000")
            break;
        else
       {
            int low=0,high=num-1;  //置当前查找区间上、下界的初值
           int r=Seareh(low, high, b);
            if (r==-1)
               cout<<"查无此词!"<<endl<<endl;
           else
               cout<<b<<"的中文意思是:"<<c[r]<<endl<<endl;
        }
    }  while(1);
   cout<<"欢迎再次使用!"<<endl<<endl;
    return 0;
}
int Seareh(int low, int high, string k)
{
    	int mid;
	do
	{
		mid=(low + high) / 2;
		if(e[mid]==k)
		{
			return mid;         //查找成功返回
		}else if(e[mid]>k)
			high=mid-1;        //继续在e[low..mid-1]中查找
		else
			low=mid+1;           //继续在e[mid+1..high]中查找
	}while(low<=high);
	return -1;                    //当low>high时表示查找区间为空,查找失败,也可返回-9等只要数组中没有即可。
}

15--5一下午的结晶,娜氏电子词典。_第1张图片

当做了这么久运行却错的时候真的不开心,还不是0错误0警告。。

不告诉我我怎么改,可是当看到它查出第一个词的时候,

心情就好了。。。

你可能感兴趣的:(15--5一下午的结晶,娜氏电子词典。)