Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with iostream,first write file in Binary mode then convert to and save ASCII
    primarykey
    data
    text
    <p>I am using iostream to collect data from a device.First I Write file in ASCII mode,it works well,but taking quite alot of time.Then I switsch to write in Binary mode and it is faster.</p> <pre><code>float dist[41616]; ofstream d_ofs( "numbers.dat",ios::out |ios::app|ios::binary); // this is from the device API getting distance datas res = GetDistances (hnd, dist, sizeof dist); d_ofs.write((char*)&amp;dist,sizeof dist); d_ofs.close(); </code></pre> <p>After the data collection,I have to convert the data inside "numbers.txt" to be readable by my tutor, in a txt file.I assume it is to change binary raw data to ASCII. so I read the file first and then write in ASCII format.</p> <p>I get numbers,but unfortunately they are not the right numbers.I guess there should be special format for this convert process.But so far I have not found the solution due to my poor coding knowledge.So can anyone give me a hand? Many thanks in advance.</p> <p>Here is my code:</p> <pre><code>double fnum[41616]; // here is the mistake,it should be float[] ifstream in("numbers.dat", ios::in | ios::binary); in.read((char *) &amp;fnum, sizeof fnum); MessageBox("Read File done"); ofstream fout("output.txt"); for(int k=0; k&lt;41616; k++) // show values read from file fout &lt;&lt;dec&lt;&lt;"\t" &lt;&lt; fnum[k] ; in.close(); fout.close(); </code></pre> <p>Conclude:</p> <p>The stupid mistake by me is in the data type.I wrote double[] instead of float[] in the second part.It is really embarrasing.Hopefully this post can help beginners like me.</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.
 

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