diff options
| author | Chanin Timbal <[email protected]> | 2024-04-27 14:05:17 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-04-27 14:05:17 -0700 |
| commit | f94af69b62058b241e569b973a136afb4d331d46 (patch) | |
| tree | 6333c9062e329593e5d7cae8a1c94bc46391a426 /CST 126/Homework 2/Homework2/helpers.hpp | |
| parent | Completed Program of Currency Conversion (diff) | |
| download | archived-homework-1-chaninnohea-f94af69b62058b241e569b973a136afb4d331d46.tar.xz archived-homework-1-chaninnohea-f94af69b62058b241e569b973a136afb4d331d46.zip | |
Homework 2 first commit
Diffstat (limited to 'CST 126/Homework 2/Homework2/helpers.hpp')
| -rw-r--r-- | CST 126/Homework 2/Homework2/helpers.hpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/CST 126/Homework 2/Homework2/helpers.hpp b/CST 126/Homework 2/Homework2/helpers.hpp new file mode 100644 index 0000000..0aa6251 --- /dev/null +++ b/CST 126/Homework 2/Homework2/helpers.hpp @@ -0,0 +1,88 @@ +#ifndef HELPERS_HPP +#define HELPERS_HPP + + +//file reading things +inline char* ReadTextFromFile(const char* fileName, char* buffer) +{ + return buffer; +} + +inline char* ReadFileAsBinary(const char* fileName, char* buffer) +{ + try + { + //open the fstream in input mode, with binary mode + std::fstream file(fileName, std::ios::in | std::ios::binary); + + if (!file.is.open()) + { + std::cerr << "Could not open file for binary input: " << fileName; + return buffer; + } + + file.seekg(0, std::ios::end); + + std::streamsize size = file.tellg(); + + file.seekg(0, std::ios::beg); + + delete[] buffer; + + buffer = nullptr; + + //size the buffer with a new + buffer = new char[size]; + + file.read(buffer, size); + + file.close(); + + return buffer; + } + catch (const std::exception& ex) + { + std::cerr << "Exception during binary file input: " << fileName << "was not successfully streamed to binary"; + ex.what() + return buffer; + } +} + +//file writing things +inline bool WriteTextToFile(const char* fileName, const char* fileContents) +{ + std::ostream file(fileName); + + if (!file.is_open()) + { + std::cerr << "Could not open file: " << fileName; + return false; + } + + file << fileContents; + + file.close(); + + return false; +} + +inline bool WriteFileFromBinary(const char* fileName, const char* buffer) +{ + return false; +} + + + + + + + + + + + + + + + +#endif
\ No newline at end of file |