-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// outputWriter.cpp | ||
// black-scholes | ||
// | ||
// Created by lyndskg on 7/19/23. | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "outputWriter.h" | ||
|
||
using namespace std; | ||
|
||
|
||
// Include the declaration of the fast_io function | ||
extern void fast_io(); | ||
|
||
// ---------------------------------------------------------------------------- | ||
// "outputWrite" Class Member Function Implementations | ||
// ---------------------------------------------------------------------------- | ||
|
||
// Default constructor. | ||
outputWriter::outputWriter() { | ||
// Call fast_io to optimize I/O speed | ||
fast_io(); | ||
} // outputWriter() | ||
|
||
|
||
// Default destructor. | ||
outputWriter::~outputWriter() {} | ||
|
||
|
||
void outputWriter::writeToConsole(const string& data) { | ||
cout << data; | ||
} // writeToConsole() | ||
|
||
|
||
|
||
void outputWriter::writeToFile(const string& filename, const string& data) { | ||
ofstream outputFile(filename); | ||
|
||
// If the file is able to be opened: | ||
if (outputFile.is_open()) { | ||
outputFile << data; | ||
outputFile.close(); | ||
|
||
cout << "Data written to file: " << filename << '\n'; | ||
|
||
// If the file is unable to be opened: | ||
} else { | ||
cerr << "Error: Unable to open file for writing: " << filename << '\n'; | ||
} // if-else | ||
} // writeToFile() |