www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/20/18:44:30

From: lied AT lucent DOT com
Date: Mon, 20 Nov 2000 17:39:31 -0600
Original-From: lied AT marconi DOT ih DOT lucent DOT com
Message-Id: <200011202339.RAA01581@w-lied.ih.lucent.com>
To: djgpp AT delorie DOT com
Subject: Re: And nary the twain shall meet...
Newsgroups: comp.os.msdos.djgpp
In-Reply-To: <Pine.GHP.4.21.0011201344590.17687-100000@raptor.csrv.uidaho.edu>
Organization: Lucent Technologies, Naperville, Illinois, USA
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019