I am trying to print my vector in the display function, but it fails. I'm about 80% sure my syntax is correct. I have tried passing it from class to class. I am sure the file is being read in correctly because when I put my for loop in ClientProcessing()
it works fine but I want to separate them.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
// struct to hold the initial information of each client
struct Clients
{
string client_name = " "; // first and last as one line
char account_type = ' '; // C for Checking - S for savings;
double initial_deposit = 0.0; // Amount for initial deposit
};
// Prototype for Account Manager
class AccManager
{
public:
vector<Clients> client_info;
string client_name = ""; // first and last as one line
char account_type = ' '; // C for Checking / S for savings;
double initial_deposit = 0.0; // Amount for initial deposit
AccManager(){};
void set_name(string n) {client_name = n;};
string get_name(){return client_name;};
void set_type(char t){account_type = t;};
char get_type(){return account_type;};
void set_initial_deposit(double d){initial_deposit = d;};
double get_initial_deposit(){return initial_deposit;};
};
// Prototype for the UI - User interface
class UI
{
public:
void ClientProcessing();
void ShowClientInfo();
};
int main()
{
UI ui;
ui.ClientProcessing();
ui.ShowClientInfo();
}
// A module that reads in the the client data file
void UI::ClientProcessing()
{
ifstream infile;
AccManager a;
int i = 0;
cout << "Processing client information...\n";
infile.open("client_data.txt");
if(infile.is_open()){
cout << "Opened client file sucessfully! \n";
while(!infile.eof()){
while (i < 1){
getline(infile, a.client_name, '\t');
a.set_name(a.client_name);
a.client_info.push_back(Clients());
a.client_info[i].client_name = a.get_name();
i++;
}
}
}
else{
cout << "Error opening file! \n";
}
infile.close();
}
// A module to display the client info as a table
void UI::ShowClientInfo()
{
AccManager a;
cout << "Name D\n";
for(int i = 0; i < a.client_info.size(); i++){
cout << a.client_info[i].client_name; // Will not print here
}
}