aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 2/Homework2/helpers.hpp
blob: e448cc923c62f6e24f15185e30f6b40588285925 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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, size_t& size)
{
	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