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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/*
* File: main.cpp
* Author: Alpha
*
* Created on May 22, 2011, 4:53 PM
*/
#include <cstdlib>
#include <string>
#include "Users_log.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <bits/basic_string.h>
using namespace std;
vector<Userslog> userslog;
//Functions
void loadUsersLog();
void display();
/*******************************************************************************/
/* Users_log Functions */
/*******************************************************************************/
void loadUsersLog()
{
string readLine; // To read everyline
size_t pointer_str; // Find the position of string
string temp_action, temp_time, temp_name, temp_uid, temp_clearance, temp_comment,temp_status;
// Open the file for read only
ifstream openFile;
openFile.open("Users_log.txt", ios::in); // Read the data file
if(openFile.is_open()){
string temp;
openFile.seekg(0, ios::end);
if (openFile.tellg() == 0)
openFile.close();
else {
openFile.seekg (0, ios::beg);
while(!openFile.eof()){
getline(openFile,readLine);
pointer_str = readLine.find(":");
temp = readLine.substr(pointer_str + 1);
temp_action = readLine.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_time = readLine.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_name = readLine.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_uid = temp.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_clearance = temp.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_comment = temp.substr(0, pointer_str);
pointer_str = temp.find(":");
temp = temp.substr(pointer_str + 1);
temp_status = temp.substr(0, pointer_str);
if(temp_action != ""){
userslog.push_back(Userslog(temp_action, temp_time, temp_name, temp_uid, temp_clearance, temp_comment,temp_status));
}
}
// Must close the file
openFile.close();
}
} else {
// Show error message, if could not open the file
cout << "Error: Could not open the file." << endl;
}
}
// Function display: display users log
void display()
{
cout << "No.\tItem\t\tTime" << endl;
cout << "===============================================================================" << endl;
int counter = 1;
vector<Userslog>::iterator it;
for (it = userslog.begin(); it != userslog.end(); ++it) {
cout << counter << ".\t" << it->getAction() << "\t\t" << it->getTime() << "\t\t" << it->getName() << "\t\t" << it->getUID() << endl;
counter++;
}
}
int main()
{
loadUsersLog();
return 0;
}
|