Hello winter89,
When it comes to files I like to use this:
1 2 3 4 5 6 7 8 9 10 11
|
const std::string inFileName{ "" }; // <--- Put File name here.
std::ifstream inFile(inFileName);
if (!inFile)
{
std::cout << "\n File " << std::quoted(inFileName) << " did not open." << std::endl; // <--- Requires header file <iomanip>. Or reverse the comments.
//std::cout << "\n File \"" << inFileName << "\" did not open." << std::endl;
return 1;
}
|
If the file did not open the return statement leaves the program until you fix the problem.
The only difference for an output file is I change "in" to "out" and "return 1" to "return 2".
This will eliminate the need to run the rest of "main" with an if/else statement. It may work, but it is bad form.
The while loop is good for reading the file.
I am not sure what this part is or what you are trying to do with it?
1 2 3 4
|
priceCount = 0;
priceTotal = 0;
priceCount++;
priceTotal += price;
|
If you have not worked up any code yet, please do so and post it.
Bits and pieces out of context are not helpful until you have a program that can be compiled and tested.
It is always best to provide enough of a program that can be compiled and tested and contain enough do duplicate any error you may have.
Speaking of errors it is also best to post the complete error message that the compiler gives you. Those who read it will understand the message better and can explain what you do not understand.
Andy