Input File Stream

  1. Design a program to request the user to input the name of a file.
  2. The format of the file is plaintext. In each line there is an integer. The total length of the file is unknown.
  3. Use "ifstream" to read integers from the file. Calculate the summation. Output the number of integers and the value of summation.
  4. Because you cannot predict the length of the data file in advance, your program must be flexbile to handle files with arbitrary number of lines. You may find the following code helpful:
    
    	while (fsIn >> n)
    	{
    	    sum += n;
    	    count++;
    	}
    
    

Suppose in your working directory you have a file "a.dat" (you may create this file by "nano" editor):

1
2
3
4

You program may run as follows:

Please input the filename which stores integers -- a.dat

There are 4 integers; summation is 10