By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,819 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,819 IT Pros & Developers. It's quick & easy.

Beginner needs help reading from .txt file!

P: 13
Hi,

I have just started using C++ (Borland compiler) and I want to read the data in a .txt-file. The txt file looks like this:

Arg 2 12.87
His 25 7.4
His 29 6.9

I would like to put the data in a struct {string, integer, float} where the rows in the struct are the same as the rows in the file. How can I do that?
I know how to read the lines (using getline) from a txt file, but not how to extract theinteger and float numbers from the string.

Thanks for the help!
Sep 26 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
look up the functions

strtol
strtof

or the C++ way would be to verify the string data is correct and create a string stream then just use the >> operators to get int and float data.
Sep 27 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.