I think you want to use something like a std::map<std::string,std::string>
, where yo have one word as key for a specific language (please read explanations from the comments):
std::map<std::string,std::string> dictionary;
ifstream in;
in.open("Q3.dic");
std::string line;
while(getline(in, line)) { // Read whole lines first ...
std::istringstream iss(line); // Create an input stream to read your values
std::string english; // Have variables to receive the input
std::string french; // ...
if(iss >> english >> french) { // Read the input delimted by whitespace chars
dictionary[english] = french; // Put the entry into the dictionary.
// NOTE: This overwrites existing values
// for `english` key, if these were seen
// before.
}
else {
// Error ...
}
}
for(std::map<std::string,std::string>::iterator it = dictionary.begin();
it != dictionary.end();
++it) {
std::cout << it->first << " = " << it->second << std::endl;
}
See a Live Working Sample of the code.
Upon my note in the code comments, you may have noticed it might be necessary to handle non unique english -> french
translations. There are cases where one english
keyword in the dictionary may have more than one associated translations.
You can overcome this either declaring your dictionary like this
std::map<std::string,std::set<std::string>>> dictionary;
or
std::multi_map<std::string,std::string> dictionary;