This is my very first fstream program, and it is completely confusing to me haha.
1. Consider the following incomplete C++ program:
A. Write a statement that includes the header files fstream, string, and iomanip in this program.
B. Write statements that declare inFile to be an ifstream and outFile to be an ofstream variable.
C. The program will read data from the file inData.txt and write output to the file outData.txt. Write statements to open both of these files, associate inFile with inData.txt, and outFile with outData.txt.
D. Suppose that the file inData.txt contains the following data:
Randy Gill 31
The numbers in the first line represent the length and width of a rectangle.
The number in the second line represent a radius of a circle.
The third line is a first name, last name, and age.
The fourth line is a savings account balance, as well as an interest rate.
The fifth line containts an Uppercase letter between A and Y(inclusive).
Write statements so that after the program executes, the contents of the file outData.txt are shown below. If necessary, declare additional variables. Your statements should be geenral enough so that if the content of the input file changes and the program is run again (without editing and recompiling), it outputs the appropriate results.
**Here is what I have so far(Granted, I have no idea if this is even the right approach):
double length; //variable declarations are correct
inFile >> length >> width;
outFile << length << width; //just add an endl after these so it look similar to the file given
inFile >> radius;
outFile << radius;
inFile >> name >> age;
outFile << name << age; //The file reads "Randy Gill", note that ifstream
//files take whitespaces as the end of reading, which means you're reading
//Gill into age
inFile >> savings >> interest;
outFile << savings << interest;
inFile >> letter;
outFile << letter << endl;
//simple enough, use cout statements to display
//contents of your vars
Alright, I think I'm understanding it. You say that I'm not writing anything into the file with the "ofstream outFile;" But in Part C of the question above, unless I'm interpreting it wrong, says that I need to write data into the outFile.txt.
"C. The program will read data from the file inData.txt and write output to the file outData.txt. Write statements to open both of these files, associate inFile with inData.txt, and outFile with outData.txt."