Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Binary File to Structure Function
    primarykey
    data
    text
    <p>I have a struct:</p> <pre><code> struct zipType{ int postalCode; double longitude; double latitude; }; </code></pre> <p>And I have a function called zipToCout:</p> <pre><code> void zipToCout(zipType zip){ cout &lt;&lt; "Postal Code = " &lt;&lt; zip.postalCode &lt;&lt; "\tLongitude = " &lt;&lt; zip.longitude &lt;&lt; "\t\tLatitude = " &lt;&lt; zip.latitude &lt;&lt; endl; } </code></pre> <p>now I need a function to read a binary file into a zipType struct. The function prototype is supposed to be <code>void binRead(zipType *zip, fstream *input);</code>. The only way I can get close to this is by changing the prototype to this <code>void binRead(zipType &amp;zip, fstream &amp;input)</code>. With that, Here is what I currently have for the function:</p> <pre><code> void binRead(zipType &amp;zip, fstream &amp;input){ int temp; double temp2; zipType tempZip; tempZip = zip; //cout &lt;&lt; "Reader at location " &lt;&lt; input.tellg() &lt;&lt; endl; input.read((char*)&amp;temp,sizeof(int)); tempZip.postalCode=temp; input.read((char*)&amp;temp2,sizeof(double)); tempZip.longitude=temp2; input.read((char*)&amp;temp2,sizeof(double)); tempZip.latitude=temp2; zipToCout(tempZip); } </code></pre> <p>This is the output I get when I run this on my sample.bin file:</p> <pre><code> Postal Code = 64501 Longitude = 2.61457e-261 Latitude = -7.13357e+288 </code></pre> <p>What I need help with is reformatting the function to use <code>*</code>'s instead of <code>&amp;</code>'s and fixing how to read the file into the three variables correctly. Thanks for looking! Also, I only have to read one zipType from the file at this point. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload