문제

I'm only starting in C++ and am having difficulty understanding certain things. I have a MIDI file and I want to retrieve the hexadecimal string, as detailed here .

How can I extract the hexadecimal string of information from a MIDI file that I read into my C++ program?

도움이 되었습니까?

해결책

A byte array is a byte array... as far as I know there isn't a specific kind for MIDI data. Not knowing what OS you're working with makes it difficult to say what specific functions to use, but you would just allocate a block of memory, open the file, read the file's data into that memory block, and close the file. From there, you can work with the data in any way you please.

다른 팁

main(){

ifstream::pos_type size;
char * memblock;

ifstream file ("Dvorak_NewWorld.mid", ios::in|ios::binary|ios::ate);
ofstream output;
output.open("output.txt");
  if (file.is_open())
  {
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);
    file.close();

    cout << "the complete file content is in memory" << endl;

    std::string tohexed = toHex(std::string(memblock, size), true);
    output << tohexed << std::endl;
    output.close();
   }

  return 0;
}

string toHex(const string& s, bool upper_case)
{
    ostringstream ret;

    for (string::size_type i = 0; i < s.length(); ++i)
        ret << std::hex << std::setfill('0') << std::setw(2) << (upper_case ? std::uppercase : std::nouppercase) << (int)s[i];

    return ret.str();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top