Question: Use c++ Write a program that prompts the user for the name of a file and then tries to open it. The open function needs
Use c++
Write a program that prompts the user for the name of a file and then tries to open it. The open function needs a C-style string instead of a C++ string. Fortunately there is a function called c_str() that will give you the C-style string version of a C++ string. For example, instead of saying "inputFile.open(filename)", you can say "inputFile.open(filename.c_str())". If the file is there and can be opened, the program should read the list of integers in the file, which will appear one to a line as in the following example:
14
9
12
-6
-30
8
109
Note:
This example is just to demonstrate the format of the input file. Your program would not print these values out to the console or to the output file. The program will then add together all the integers in the file, open an output file called sum.txt, and write the sum to that file (just that number - no additional text). Remember to close both the input and output files. If the file is not there (or is there but couldn't be opened for some reason), the program should just print out "could not access file".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
