this is my whole program:
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
|
//main
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>
#include "LReader.h"
int main(int argc, char* argv[]) {
LReader l("/home/kaertech/stats_20140801_061314.log");
std::string contents;
std::string strDateStart = "2014-08-01";
std::string strDateEnd = "2014-08-10";
contents = l.getLogs(strDateStart, strDateEnd);
std::cout << "File content is: " << std::endl;
std::cout << contents << std::endl;
//LReader.h
class LReader {
public:
LReader(const std::string & pth) : path(pth) { };
std::string getLogs (const std::string & c, const std::string & d);
private:
std::fstream logFile;
std::string path;
//LReader.cpp
std::string LReader::getLogs (const std::string & c, const std::string & d){
std::ifstream logFile(path.c_str());
if (logFile.fail())
{
std:: cout << "Can't open file" << std::endl;
void exit ();
}
std:: string line2;
while (getline (logFile,line2) )
{
std::size_t f1 = line2.find(c);
std::size_t f2 =line2.find(d);
if (f1!=std::string::npos )
f1++;
if ( f2!=std::string::npos)
break;
std::cout << line2 << std::endl;
}
}
|
contents of /home/kaertech/stats_20140801_061314.log
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-05 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-06 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-07 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-08 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-09 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-10 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-11 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-05 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-07 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-09 07:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 07:13:14,Name,4.5,CustomUnit,CustomType
Here's my output:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-05 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-06 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-07 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-08 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-09 06:13:14,Name,4.5,CustomUnit,CustomType
Segmentation fault (core dumped)
errors: it should display until
2014-08-10 and Segmentation fault (core dumped)
Another problem is I can't change main function and I also have a problem in returning my output to the main
Thanks for the suggestions