-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.cpp
More file actions
41 lines (33 loc) · 1.17 KB
/
ReadFile.cpp
File metadata and controls
41 lines (33 loc) · 1.17 KB
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
#include "ReadFile.h"
#include <iostream>
#include <string>
ReadFile::ReadFile(const char* file_name)//Constructor. Used to open the file and set the closed and _eof bits. No return.
{
input_file.open(file_name);
closed = false;
_eof = false;
}
/*ReadFile::~ReadFile()
{
}*/ //Destructor. C++ will generate one for my memory that isn't dynamically allocated.
bool ReadFile::eof()//Use to get the status of the _eof bit.
{
return _eof;
}
void ReadFile::close()//This function closes the file it the closed bit hasn't been set to true, and the sets it to true. Returns void.
{
if (!closed)
{
input_file.close();
closed = true;
}
}
String* ReadFile::readLine()//Reads in a line from the opened file and sends it to a String* variable
{
if (closed) return NULL;//If either of these bits are set, we don't want to put garbage in our String*. So return NULL.
if (_eof) return NULL;
string text;
_eof = !(getline(input_file, text));//Sets the _eof bit to true if getline reaches the end of the line.
String* str = new String((const char*) text.c_str());//Uses a constructor from String class to make a new String* variable to return.
return str;
}