I'm trying to read the ID3 tag from a file. For now, I print out the string that I've read and I can see the title, year and so on but in the specs it says that the first 7 bytes contain ID3, the version, some flags and the size of the tag. But I can only see the ID3-string. This is some of the output:
ID3 C @TRCK 4/16TIT2PossibilityTP

It doesn't get pasted here but there are symbols between the ID3, C and the @ and in other places. ( I had to replace them with spaces but actually there are like 5 symbols in between) So the bytes I need are being read but not outputted. I guess they are the C and @ but I need them in integer/double format. It should be 1098058bytes for this file but it is variable for each file.

This is my code:

std::strings = "04 Possibility.mp3";
    int tagsize = 50;

    char buffer[tagsize];

    std::ifstream mp3File(s.c_str(),std::ios::binary);
    mp3File.getline(buffer, tagsize);

    std::string outp("");
    for (int i = 0; i <= tagsize; ++i){
    std::cout << outp << std::endl;

The tagsize is just for debugging purposes, its size is 1098058bytes which crashes the output.

Anyone got any ideas on how to get the 1098058 from the file header?

Thanks, Jasper

7 Years
Discussion Span
Last Post by Salem
Featured Replies
  • 1
    Salem 5,138   7 Years Ago

    [url]http://en.wikipedia.org/wiki/ID3[/url] They're not all-text. They're not always at the beginning, They're not always present. They're not always ASCII. You can't just open the file and read a string, and hope it all works. Read More

for (int i = 0; i <= tagsize; ++i)

This goes one beyond the array bounds.

int tagsize = 50;

    char buffer[tagsize];

Since tagsize is not const, it would seem that you are using a nonstandard extension. Be aware of that.


Ok, changed that but what is a nonstandard extention?
Still no difference in the output though.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.