I am confused about the inability for this code to work. All others that have used visual studio have gotten this to function, however I am trapped in an Xcode universe (which I am discovering is the programming equivalent of being trapped inside a laundry bag of used jock straps)
I put the code down below, but cannot go any further since the ability for Xcode to even open a file doesn't seem to work.
I cannot include screenshots, but I have tried placing the files in the File folder, the Product folder, copies of both in both folders, and each time it fails.
(1) Your compiler (like mine) may be set to compile the original C++ standard (C++98). Opening files requires a C-string, not the newer string. See if changing line 33 to infile.open(filename.c_str());
and line 44 to outfile.open(filename.c_str());
works. (The member function c_str() converts a string to the older null-terminated character string type - look it up.)
(2) I had to add #include <cstdlib>
amongst the headers in order to use exit(1).
(3) I assume that whatever file you are trying to read from should be in the same folder/directory as your source code. Check this.
Visual studio and Xcode are unnecessarily complex suites of software for learning. I should use g++ (from MinGW), run from the command line. Then at least you know where all your files are.
Please provide feedback as to whether any of this works. I had no problems running your program once I had made changes (1) and (2) above, and adding some input/output lines to check that I was reading correctly.
testscores = x / report = y
I tested it the following ways (my best as the visual representation of the left column):
File:
main.cpp
x.txt
y.txt
Products
File
---AND---
File:
main.cpp
Products
File
x.txt
y.txt
I attempted to open the files as x/x.txt/ and y/y.txt
Every time I got the same error message that <filename> would not open. I also tried to make a two variations of the file in a .txt format and a .rtf format.
If the input file is called x.txt then reply to the prompt as x.txt
I assume this is just a simple text file (that you have already created outside of your program).
Nothing wrong with your C++ code. Open Windows explorer and check that main.cpp (presumably the name of your source code?) and x.txt are in the same folder. Use the notepad text editor to check that they are the files you require. Your output file is irrelevant, since it is to be created by the program.
I have no idea what you mean by File: and Products:, but then I don't use Xcode.