/*
*copyright (c) 2014, 烟台大学计算机学院
*All rights reserved
*作者:王争取
*日期:2014.12.22
*文件名称:test.cpp
*版本号:v1.0
*问题描述:读取文件,输入要查询的单词,输出单词意思和词性
*输入描述:输入要查询
*程序输出:输出单词意思和词性
*/
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>
using namespace std;
struct Word
{
string english;
string chinese;
string word_class;
} word[8000];
int main()
{
string x;
ifstream infile("dictionary.txt",ios::in);
if(!infile)
{
cerr<<"open error"<<endl;
exit (1);
}
int i=0;
while(infile>>word[i].english>>word[i].chinese>>word[i].word_class)
++i;
infile.close();
cout<<"请输入要查询的单词并以0结束"<<endl;
while((cin>>x)&&x!="0")
{ bool flag=false;
for(int j=0; j<i; j++)
if(x==word[j].english)
{
flag=true;
cout<<word[j].english<<'\t'<<word[j].chinese<<'\t'<<word[j].word_class<<endl;;
break;
}
if(flag==false) cout<<"There is not this word"<<endl;
}
return 0;
}
第十七周 项目7 电子词典结构体版

最新推荐文章于 2018-11-26 13:40:29 发布
