- I did # 1 .. but i am really confused on what i am supposed to do on # 2,3, and 4.
1. Read in an input file name. If it is not a valid file continue to prompt the user until a valid file is
read in.
2. Read in an output file name. If it exists it will be over written.
3. All output should go to the output file instead of standard output.
4. Write the input file to the output file and make all alphabetic characters upper case.
#2 Means it wants you to get the user input for a filename which will be written, making a standard std::ofstream(output_file) will automatically overwrite the given file if it exists, so don't worry about that.
#3 Is saying the output of the program should go to the output file, kinda badly worded, it is closely intergrated with #4.
#4 Wants you to read in the input file, make it all letters upper case, then write it to the output file
In essence you will want something like this:
1 2 3 4 5 6 7
{
Get InFileName
Load InFileName to Memory
Make Memory Changes
Get OutFileName
Write Memory to OutFileName
}
My friend and i both thank you haha we asked the same question . This program is pain in the butt. so how do i read in the input file and write it to the output file. Brain is already hurting haha.
The intermediate between both operations (i.e the reading in to the writing out) process can be done in numerous ways.
FIrst you open the file to be read:
std::ifstream(filename);
Makes sure to do some error checking before continuing, if you are completely new to C++ and file streams I suggest looking at calcushtag's link.
After opening the file you have to choose how you want to store the contetns of this file for further inspection/operation. You could load the file into a character vector, then interate through to find any letters, if so make them uppercase. Then write the contetns of the vector 1 byte at a time to the writing file till you reach the end.
Or you could load the file into a string vector, then iterate through each string to find the letters and make them uppercase.
It is very possible you could translate the input file to the output file in a single pass, meaning in 1 loop you read, check and write.