Storing numerical value from a binary file into an array- C++ -
I am trying to read numerical data from a binary file with double values and store it in an array named My Array I am When I print my Arya, nothing is being shown, like my arrow has never been filled. Any help is appreciated.
int main () {int file_len; Infinite Infile; Infile.open ("mybinfile.bin", iOS :: binary | iOS :: In); If (Infile.is_open ()) {cout & lt; & Lt; "Error opening file." & Lt; & Lt; Endl; } And {const int file_len = 100; Std :: vector & lt; Four & gt; MyVect; MyVect.resize (file_len); Int i = 0; Infile.read ((Four *) (& Temp), Size (four)); MyVect [i] = temporary; While (Infile.eof ()) {myVect [i] = temp; I ++; Infile.read ((Four *) (& Temp), Size (four)); } For (int i = 0; i & lt; 100; i ++) {cout & lt; & Lt; I & lt; & Lt; ":" & Lt; & Lt; MyVect [i] & lt; & Lt; Endl;}} infile.close (); Return 0; }
here
infile.read (( Char *) and Maya, File_Len * size (double));
You repeat the Indicator Indicator . It should be
infile.read ((* four *) myArray, file_len * sizeof (double));
I wonder why you have not seen a crash, since writing in random memory almost never changed well.
Comments
Post a Comment