forked from scott/threaded_network_chat
initial commit
This commit is contained in:
44
log.cc
Normal file
44
log.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "public.h"
|
||||
#include "log.h"
|
||||
|
||||
// gets the number of lines in a file. returns -1 if there was an error.
|
||||
int
|
||||
linesInFile(string path)
|
||||
{
|
||||
ifstream file(path);
|
||||
if (!file) {
|
||||
return 1;
|
||||
} else {
|
||||
int lineNum = 0;
|
||||
string line;
|
||||
|
||||
int num = 0;
|
||||
while (getline(file, line))
|
||||
num++;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
// appends a line of text to the end of a given file. returns 0 if the file
|
||||
// existed, 1 if it didn't work
|
||||
int
|
||||
writeToFile(string path, string line, bool incLineNum)
|
||||
{
|
||||
ofstream file;
|
||||
file.open(path, ios_base::app); // open the file in append mode
|
||||
|
||||
if (file.is_open()) {
|
||||
file << line << endl;
|
||||
// this probably would help but theres too much broken stuff
|
||||
// right now to be sure if (incLineNum)
|
||||
//{
|
||||
// linePos++;
|
||||
// }
|
||||
return 0;
|
||||
} else {
|
||||
// do something if it didn't work
|
||||
return 1; // i guess that's good enough for now
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user