The practice prompt is as follows:
Write a program that reads the list /users/calendow/assignments/shortest-word and prints out the single shortest word in it.
Here is what I have so far:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream inputFile("/users/calendow/assignments/shortest-word");
return 0;
}
So my first guess is to open the file to find the shortest word. It would probably be best if I follow the path to open the file and see what the list contains. How do I do that?
Secondly where do I go from here? I am completely lost. Any help is appreciated.
After you have opened the file you can read the first word and store it in a variable. After that you read word after word and compare it to the shortest word so far. If it is shorter you set it as the shortest word. Then you can close the file and print the shortest word.
If you need any help in dealing with files have a look at this tutorial. http://www.cplusplus.com/doc/tutorial/files/