Thank you all for your responses. If I'm not mistaken, all you say is: read the string and then parse it. But, my file may not have newlines at all and you don't know how large it may be (it may be stdin).
So, I need to read one "word" at a time and convert it to a float. @mratsim showed a solution using streams, but as far as I can tell, readFloat32 and company read _binary_ data in the file. (I tested the sample code, and got strange floating point numbers from a sample ascii file.) What I'm looking for, therefore, is the ascii version of readFloat32 and friends, which automatically skip blanks/newlines/tabs , just like cin >> i of C++ or the formatted read of Fortran. If there is no ready-made functions like that, I would need to write ones, but to do so, would I have to read a character at a time? Or is there a read function that stops at a specified delimiter? Another related question: Is there an official mechanism to convert between objects and their string representations? For example, in Ruby, there is the pair to_f and to_s: > "3.14".to_f # gives 3.14 (float) 3.14.to_s # gives "3.14" (string) > "3.14".to_f.to_s # gives "3.14" In Haskell, show and read form such a pair. If you have such an official mechanism, you just define to_s or show for your own type (class) and voila the standard output functions (like echo of Nim) start to be able to print values of your own type.
