Skip to content

Commit

Permalink
Create outputWriter.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
lyndskg committed Jul 21, 2023
1 parent f8a19b6 commit 2f76042
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/outputWriter.cpp
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()

0 comments on commit 2f76042

Please sign in to comment.