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;
}
Right now my code only works if I type only one word. But if I type in a sentence it won't ouput anything.
So my question is if the user input: hello good morning, How would I search for hello and good morning in my text file and output it.
This is an example of the text file:
today aujourd'hui
good bon
good morning bonjour
afternoon après-midi
good evening bonsoir
much beaucoup