using class to retrieve and store data
I'm trying to write a class that when called the first time, it retrieves data from a file where the file contains a log line specific for a particular user.
Whenever it's called after that, want to call it to get a specific user data setting such as email address or last date contacted, without re-quering the file.
Here's my code. How far off am I?
Code:
#include <stdlib.h>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
//#include <cstdlib>
//#include <cstring>
class UserSettings
{
private:
char username[30];
char lastdatecontacted[10];
char emailaddr1[50];
char emailaddr2[50];
void GetUserSettings(char currentuser[30])
{
ifstream fin;
fin.open("config.txt", ios::in);
if(fin.fail())
{
cout << "Error: Unable to open file.\n";
return 0;
}
char detailline[140];
while(!fin.fail() && !fin.eof())
{
fin.getline(detailline, 11, '\n');
if (detailline == currentuser)
{
//hmmm, is substring 0 or 1 based?
username = detailline.substring(1,30);
lastdatecontacted = detailline.substring(31,10);
emailaddr1 = detailline.substring(41,50);
emailaddr2 = detailline.substring(91,50);
}
}
fin.close();
}
public:
UserSetting(char currentuser) : whatgoeshere(andhere)
{
//pull from file???
GetUserSettings(currentuser)
}
//member functions which do something with toxin
int GetLastDateContacted() //return the value of toxin
{
return lastdatecontacted;
}
void AlterLastDateContacted(int Date_Contacted) //set toxin to Toxin_Value
{
lastdatecontacted = Date_Contacted;
}
};
void main()
{
char LastDateContact[10];
LastDateContact = UserSettings("bobsmith").GetLastDateContacted;
}