I am trying to create object that will store inside vector using pointers
I can store object inside vector when I don t use pointers, but when I try to use pointers I can not do that
// created class that combine some attributes for file "datum" = date, "vrijeme" = creation of file etc.
class datoteka{
public:
string datum;
string vrijeme;
string velicina;
string ime;
datoteka();
datoteka(string datum, string vrijeme, string velicina, string ime)
{
this -> datum = datum;
this -> vrijeme = vrijeme;
this -> velicina = velicina;
this -> ime = ime;
}
~datoteka();
};
int main()
{
vector <datoteka> fajlovi;
string linija;
string prva;
int i = 0;
datoteka * pokObjDatoteke;
pokObjDatoteke = new datoteka();
std::ifstream pisi("list.txt"); //file is open
while(getline(pisi,linija)) //get first line of file
{
string vrijednost;
stringstream red; //create stream from line
string datoteka[4]; // create array to store seperate information
red << linija;
while(!red.eof() && i != 4) // since line containt lot of tabs i
read just first for values
{
red >> vrijednost;
datoteka[i]= vrijednost;
i++;
cout << vrijednost << " ovo je vrijednost" << endl;
}
pokObjDatoteke->datum = datoteka[0];
pokObjDatoteke->vrijeme = datoteka[1];
pokObjDatoteke->velicina = datoteka[2];
pokObjDatoteke->ime = datoteka[3];
fajlovi.push_back(*pokObjDatoteke); /**** problem ****
}
return 0;
}
I want to store objects in vector, instead I get just some memory location, probably from pointer but how can I store object and not address