Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for numbers from a a text file

Status
Not open for further replies.

RSTR

Programmer
Mar 25, 2000
27
US
Is there a way to have searched through a text file like:

char line[256];
ifstream afile("c:\somefile.txt");
afile.getline(line, 255, '\n');

and assume that the first line of the text file was:
256.4223
That would mean that line[0] is = 2, [1] = 5 etc....

now lets say I have a float:
float x;
and I want x to equal the scanned number, 256.4223.
I can't say:
x = static_cast<float>(line);

this doesn't work. so what can I do to make x equal a number that was input from a text file?

-RSTR benthecat@hotmail.com

 
that works. Also, I discovered the old C method:

sscanf(); I can't remember the syntax exactly right now, but it works great for parsing files =-)

thx -RSTR benthecat@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top