#include <iostream>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <vector>
#include <dirent.h>
#include <string.h>
#include <conio.h>
#include <algorithm>
#include <set>
#include <typeinfo>
#include "Mp3TaggedFile.h"
using namespace std;
typedef std::vector<std::string> fileVect;
typedef std::set<std::string> mp3Names;
typedef std::vector<Mp3TaggedFile *> mp3List;
int getTitle(char *file,mp3List &listOfFiles);
fileVect getFiles(std::string directory);
string compare (mp3Names names);
string getStr (mp3Names iter);
/*****************************/
typedef struct
{
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
unsigned char genre;
} mp3Tag;
int getTitle(char *file, mp3List &listOfFiles)
{
FILE *fp = fopen(file, "rb");
if (!fp)
{
perror("File open failed");
return 1;
}
mp3Tag tag;
// Seek to 128 bytes before the end of the file
if (fseek(fp, -1 * sizeof(mp3Tag), SEEK_END) == -1)
{
perror("fseek failed");
fclose(fp);
return 2;
}
// Read the tag
if (fread(&tag, sizeof(mp3Tag), 1, fp) != 1)
{
fprintf(stderr, "Failed reading tag\n");
fclose(fp);
return 3;
}
// Make sure we've got what we expect.
if (memcmp(tag.tag, "TAG", 3) == 0)
{
//Found the tag where we expected
Mp3TaggedFile *mp3file=new Mp3TaggedFile(tag.title,tag.artist, tag.album,tag.year,tag.comment);
//cout<<tag.title<<endl;
mp3file->show();
listOfFiles.push_back(mp3file);
}
else
{
fprintf(stderr, "Failed to find TAG\n");
fclose(fp);
return 4;
}
fclose(fp);
return 0;
}
class Mp3TaggedFile
{
public:
Mp3TaggedFile(char title[30],char artist[30],char album[30],char year[4],char comment[30]);
virtual ~Mp3TaggedFile();
void show();
protected:
private:
char *title;
char *artist;
char *album;
char *year;
char *comment;
char *pathfile ;
Witam mam problem z vectorem. W funkcji tworze obiekt Mp3TaggedFile ktory zawiera informacji o pliku mp3. Do funkcji przekazuje vector. Gdy chce odczytac z tego vektora (poza funkcja) dostaje jakies smieci, a gdy czytam go tam gdzie uzywam
listOfFiles.push_back(mp3file);
jest wszystko ok. Co robie zle?