[C++] Reading a float from a file

Associate
Joined
20 Jul 2005
Posts
79
Location
Manchester, UK
Hiya there...

I'm having a right trouble over coming a problem i have encountered. Bascially, I have got a list of points in a text file. Something along these lines:

Code:
v -63.939293 53.000392
v 34.543432 43.434523
....
...
..
v 34.543432 43.434523
EOF

I need to parse the text file and place each of the float values in an array of points (which contain an x and y value). Has anybody got any suggestions of how to do this or links to tutorials?

I just can't seem to get my head around it and google isn't being very nice to me today.

Cheers for any help!

Danny.
 
Visage said:
Code:
#include <fstream>
#include <string>

int main()
{
   ifstream file("myfile.txt") ;

   std::string header ;
   float value ;

   if (file)
   {
      while(!file.eof())
      {
         file >> header ; //will get the 'v'
         file >> value ; // will get the float
         // Do something with values....
      }
   }
}

Thanks for the replies guys... Does the above code only place the first float value into the float variable and discard the second float value from the file on every line?
 
Back
Top Bottom