Mail Archives: djgpp/2000/11/20/18:44:30
In article <Pine DOT GHP DOT 4 DOT 21 DOT 0011201344590 DOT 17687-100000 AT raptor DOT csrv DOT uidaho DOT edu> you write:
>Hullo, folks:
>
>I have a text file- numbers, two decimal places, tab delimited. I'd like
>to be able to import this info into a program, and assign each number as a
>float.
>
>It seems like, using fin.getline, you can only pull the data in in char
>format. Is there a way to take char format and convert it to float, or is
>there some other import method I should be using?
Looks like C++ ... if I understand your question, it might be
as simple as not using getline:
#include <iostream>
float f1, f2;
while ( fin >> f1 >> f2 ) // Read 'em in
{
cout << f1 << "\t" << f2 << endl; // Dump 'em out
}
If the line is already in a character array, you can convert
the array using sscanf():
#include <cstdio>
float f1, f2;
sscanf(buf, "%f\t%f", &f1, &f2);
--
- Raw text -