I need to create a vector of class objects. I know that is done similarly to this:
class application{
string s;
vector<account> accounts;
for(;;){
(Imagine this is a loop and there is some code to pull the information out of a file until the end)
accounts.push_back(account(s));
};
class account{
private:
string a;
account(string init_a): a(init_a);
}
is this the correct way of doing this and if so how do I output each vector assuming there is like 10?
Well, this rather too pseudo-codish to be able to classify as right or wrong.
Your for loop, for example, is not even inside any function. And your account constructor has an intializer list which is
good, but is missing a function body. (It should take the parameter by const reference though).
Output the vector by walking the elements in the vector one by one and printing them.
1 2
for( std::vector<account>::iterator i = accounts.begin(); i != accounts.end(); ++i )
std::cout << *i << std::endl;
application.h
#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include"account.h"
#include"accountInfo.h"
using namespace std;
using namespace account_info;
using namespace exception_handling;
using account_class::account;
all the other header files are not necessary to figure out what I need. i need to know if I am pushing the application classes correctly and then I cannot figure how to overload operator<< and have it output each vector to a file in a nice fashion