-1
char option;
cout <<"What langauge would you like to translate from - English 'E' or French 'F': ";
cin >> option;
cin.ignore();
ifstream in;
in.open("Q3.dic");
size_t pos;
string phrase;
if (option == 'E')
{
cout <<"please enter a sentence in English: ";
getline(cin, phrase);
for(string english, french;
getline(in, english, '\t') && getline(in, french);
)
{
pos = english.find(phrase);
if(pos != string::npos)
{
cout << french <<endl;
break;
}
//cout << english << '\t' << french <<endl;
}
}
else if (option == 'F')
{
cout <<"please enter a sentence in French: ";
getline(cin, phrase);
for(string english, french;
getline(in, english, '\t') && getline(in, french);
)
{
pos = french.find(phrase);
if(pos != string::npos)
{
cout << english <<endl;
break;
}
//cout << english << '\t' << french <<endl;
}
}
in.close();
cout <<endl;
system("pause");
return 0;
现在我的代码,如果我键入只有一个字才有效。但是如果我输入一个句子,它不会输出任何东西。
所以我的问题是,如果用户输入:你好,早上好,我如何搜索你好,我的文本文件早上好,并输出它。
这是文本文件的例子:
今天aujourd'hui
良好的盂兰盆
早上好,卓悦
下午滑雪后-MIDI
晚上好bonsoir
多beaucoup
看起来你可以做一些研究:“stackoverflow读取文件字句”。 –
看起来你已经使用[我的代码在字典中阅读](http://stackoverflow.com/a/22772641/78845)解析用户输入,它不会这样做。如果您要让人们为您编写代码,您需要了解它的功能! – Johnsyweb
[我想从英语翻译成法语和反义词]可能的重复(http://stackoverflow.com/questions/22768038/i-want-to-translate-from-english-to-french-and-viceversa) – Johnsyweb