I am fairly new to C++ and Eclipse.
I figured out how to open an MP3 file and output the contents of the file to the console, but it is displayed in a coded format. I am trying to look for patterns so I need the fstream to be binary (or hexadecimal is fine). When I output the content of the fstream to the console I get:
File is open!
ID3 bTIT2 Stupid Song
(Truncated for simplification)
What I expect is what I see when I open the mp3 in a hex editor:
33 03 00 00 00 01 09 62 54 49 54 32 00 00
00 00 00 52 74 75 70 69 64 20 53 6F 6E 67
What am I doing wrong? Is it a console setting, an issue with it being a string? Something else entirely? Thanks for your help!
// Name : Open_A_File.cpp
// Author : Kyle Roseberry
// Description : Hello World in C++, Ansi-style
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile;
myfile.open("src/Test.mp3", std::ios::binary);
if (!myfile.is_open())
{
cout << "Cannot read file!" << endl;
}
else
{
cout << "File is open!" << endl;
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}
cout << "Done!" << endl;
return 0;
}
[Updated on: Wed, 07 October 2020 15:48] by Moderator