I have this class code in c++:
#include <iostream>
#include <cstring>
using namespace std;
enum tip{txt,
pdf,
exe
};
class File{
private:
char *imeDatoteka{nullptr};
tip t;
char *imeSopstvenik{nullptr};
int goleminaFile = 0;
public:
File(){}
File(char *i, char *imeS, int golemina, tip tip){
t = tip;
goleminaFile = golemina;
imeDatoteka = new char[strlen(i)+1];
imeSopstvenik = new char[strlen(imeS)+1];
strcpy(imeDatoteka, i);
strcpy(imeSopstvenik, imeS);
}
File(const File &f){
t = f.t;
goleminaFile = f.goleminaFile;
imeDatoteka = new char[strlen(f.imeDatoteka)+1];
imeSopstvenik = new char[strlen(f.imeSopstvenik)+1];
strcpy(imeDatoteka, f.imeDatoteka);
strcpy(imeSopstvenik, f.imeSopstvenik);
}
~File(){
delete [] imeDatoteka;
delete [] imeSopstvenik;
}
File &operator=(const File &f){
if(this != &f){
t = f.t;
goleminaFile = f.goleminaFile;
delete [] imeDatoteka;
delete [] imeSopstvenik;
imeDatoteka = new char[strlen(f.imeDatoteka)+1];
imeSopstvenik = new char[strlen(f.imeSopstvenik)+1];
strcpy(imeDatoteka, f.imeDatoteka);
strcpy(imeSopstvenik, f.imeSopstvenik);
}
return *this;
}
void print(){
cout<<"File name: "<<imeDatoteka<<"."<<(tip) t<<endl;
cout<<"File owner: "<<imeSopstvenik<<endl;
cout<<"File size: "<<goleminaFile<<endl;
}
bool equals(const File & that){
if((strcmp(imeDatoteka, that.imeDatoteka) == 0) && (t == that.t) && (strcmp(imeSopstvenik, that.imeSopstvenik) == 0))
return true;
else
return false;
}
bool equalsType(const File & that){
if((strcmp(imeDatoteka, that.imeDatoteka) == 0) && (t == that.t))
return true;
else
return false;
}
};
And i have a problem. So i have an private member 'tip' that is enum type. The problem is it doesn't print it correctly(pdf,txt or exe), it just prints 0,1 or 2. I've seen some people try to cast it in the cout but it doesn't work for me. Any help?