
please wait
In this exercise, you will write a function getIdFromFile that takes three parameters (a C++ string representing a filename, an istream, and an ostream) and returns an int. Your function should open the file with that name, which will contain up to 1000 unique usernames and ID numbers in this text-based format: jblack 179 kdavid7 230 sclaus 12 ... Your program should repeatedly read a username from the istream parameter, look up the corresponding ID number in the file, and print that ID number to the ostream on a line by itself (with no other whitespace). If there is no such username, print "error" on a line by itself. Keep reading usernames until there are none left (that is, until the istream has reached eof), and return 0. If you can not open the file, return -1. |
How would I implement the specific format for the 1000 unique usernames? |
And how would I get it to read the username then look up the corresponding ID number? |