Reading string line and double from a text file

Hi all,

Can someone please teach me how to read file containing a menu item name and its price in double per line. the sample data is given below.

Bacon and Egg 2.45

Plain egg

Coffee 0.50

Thanks in advance
Last edited on
use getline():

http://www.cplusplus.com/reference/string/getline/

to read the line from the file

then use rfind() and substr():

http://www.cplusplus.com/reference/string/string
http://www.cplusplus.com/reference/string/string/rfind/
http://www.cplusplus.com/reference/string/string/substr/

to extract the value from end

then you can use atof:

http://www.cplusplus.com/reference/clibrary/cstdlib/atof/

to get the double from the extracted string
Ok ill give it a try and let u know
thanks for the links and suggestions
Topic archived. No new replies allowed.