-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSFile.cpp
72 lines (63 loc) · 1.05 KB
/
RSFile.cpp
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
#include "include/RSFile.h"
RSFile::RSFile(const char* fileName, const char* mode)
{
m_fileName = fileName;
m_isOpen = false;
m_mode = mode;
mp_fp = NULL;
mp_fp = fopen(m_fileName, m_mode);
if (mp_fp != NULL)
m_isOpen = true;
}
std::string RSFile::ReadLine()
{
char c = ' ';
std::string out = "";
while (true)
{
c = ReadChar();
out += c;
if( c == EOF )
break ;
if(c == '\n')
break;
//}
//printf("%c",c);
//out[i] = c;
//out[i+1] = '\n';
//out[i+2] = '\0';
}
return out;
}
char RSFile::ReadChar()
{
char c = fgetc(mp_fp);
//if( feof(fp) )
//{
// break ;
// }
// printf("%c", c);
//}
}
int RSFile::Write(const char* text)
{
int count = fprintf(mp_fp, "%s",text);
if(count > 0)
return 0;
return RSFILE_ERROR_WRITE;
}
int RSFile::Write(char text)
{
int count = fprintf(mp_fp, "%c",text);
if(count > 0)
return 0;
return RSFILE_ERROR_WRITE;
}
RSFile::~RSFile()
{
if(m_isOpen)
{
fclose(mp_fp);
m_isOpen = false;
}
}