Writing data to memory in C++
<p>I want to write a a mix of int, char, real in void *data.
I am using a file pointer to run through the data block.
Now my question is that since the data type is void, I have to typecast it to int while writing integer and char for writing string. 
While typecasting I used the following sample code:</p>

<pre><code>*((int *)data+0) = 14;      //writing int
*((int *)data+4) = 5;       //writing int, left a space of 4 bytes for int
*((char *)data+8) = 'a';    //writing char
*((char *)data+9) = 'f';    //writing char
</code></pre>

<p>But then while reading the values back it didnt give the correct value.</p>

<pre><code>cout&lt;&lt;*((int *)data+0);
cout&lt;&lt;*((int *)data+3);
cout&lt;&lt;*((char *)data+8);
</code></pre>

<p>Is the way my code is written correct? I am doubtful about it as data is void.</p>
