Here is a similar question on the topic with a good description of the file:
how to read NASA .hgt binary files
I am fairly new to programming in general and my efforts thus far have been very limited. My ultimate goal is to access the elevation data and store it in a 2D array for easy access. I have been trying to read the file 2 bytes at a time, as has been suggested, but I don't know what to do next. Here is what I've got so far:
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main () 
    {
        ifstream::pos_type size;
        char * memblock;
        ifstream file ("N34W119.hgt", ios::in|ios::binary|ios::ate);
        if (file.is_open())
        {
            size = 2; 
            memblock = new char [size];
            file.seekg (0, ios::beg);
            file.read (memblock, size);
            //I don't know what to do next
            file.close();
        }
        return 0;
    }
Thanks for any help!
// SRTM_version 1201 or 3601 
int height[SRTM_version][SRTM_version]; 
for ( int r = 0; r < SRTM_version ; r++ ) {
   for ( int c = 0 ; c < SRTM_verision; c++ ) {
      height[r][c] = (memblock[0] << 8) | memblock[1];  
   }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With