I am new to this forum. I got a stuck in my work ... I have ASCII file with numerical values, and I need to read them and save them in a matrix of 2 dimensions?.... If anyone can help me please ....!!???
after I learned C++ bit and I followed your suggestions. I wrote my code. It works but not like what I need, I cannot understand why. Since I need to read an ASCII numerical file and save data in matrix of two dimensions. Any more suggestions please.
The code is:
I have another challenge which I really do not know how to solve it.
The code above reads the ascii file, but now i want to read the FLT file. This is to difficult for me to figure out.
Please if the there is any suggestion would be appreciated.
The FLT file is a Float Grid format.
You have to find information about what that file is supposed to contain.
Quite likely there will be some sort of header and the array of floats.
see http://www.cplusplus.com/doc/tutorial/files/ (the part about binary files)
basically myfile >> my_float; becomes myfile.read((char*)&my_float, sizeof(float));
The EOF flag is not set until *after* the read fails. So you will process one line of bad data using that. It is much better to put your file read operation in the while clause if possible like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// getline() returns the stream. testing the stream with while returns error such as EOF.
// so here we know that the read was a success and that line has valid data
while(ss >> my_array[row][col])
Thanks for your helps and suggestions. After I followed your suggestions and i got help from friend, I ended up with the following code which reads a flt file and store the data as a matrix of 2 D as follows:-