Question
Add the preprocessors required to give the compiler the instruction to compile the program. int main() { string filename = prices.txt; // put the filename
Add the preprocessors required to give the compiler the instruction to compile the program.
int main()
{
string filename = "prices.txt"; // put the filename up front
ofstream outFile;
outFile.open(filename.c_str());
if (outFile.fail())
{ cout << "The file was not successfully opened" << endl;
exit(1);
}
// set the output file stream formats
outFile << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
// send data to the file
outFile << "Mats " << 39.95 << endl
<< "Bulbs " << 3.22 << endl
<< "Fuses " << 1.08 << endl;
outFile.close();
cout << "The file " << filename
<< " has been successfully written." << endl;
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started