Imagine you are given a file of data about movies. It is written in such file where it was created. In that case, it might be "Germany" as well as "Great Britain". So the problem arises. I know I can read a file using a simple while loop. Doing so, however, will cause the program not to read the file properly. Let's assume that we have a file movies.txt in which it is stated:
1988 Spain Madrid, The Capital City
1988 Spain Madrid, The Capital City
1989 Great Britain Glasgow
1988 Spain Madrid, The Capital City
1988 Spain Madrid, The Capital City
Let's say the file line was: 1989 United States New York
Is the country "United", and city "States New York"?
Or is it "United States New" and the city "York"?
My point is, your file format is simply ambiguous...
Is this homework? Are you allowed to change the structure of your input file?
If so, add a comma between {Country Name} and {City Name and Phrase}, and parse the file using std::getline, delimited by a comma.
ex: 1988 United States, New York, The Largest City
will get split by the first comma, so the country will become {United States} and the city will become {New York, The Largest City}
If not, you will have to be given some limited possibilities of options to choose from, for example, if the first word is "Great" or "United", concatenate the next word into the country name. Of course, this will get complicated for countries like the United Arab Emirates, where you'll need two layers of conditions to check.
Ok then, so maybe there is a possibility of distinguishing the parts by what they are divided by? '\t' 's are what is between them while ' ' occur only in the phrases.