Reading contents And Calculating

HELP!!I need to know whether in c++ we can read values from a .txt file and use it to calculate something.

EXAMPLE:-
In the TEXT FILE-
FoodCode: f2,f3,g2
where anything of type 'f' is 50bucks and of type 'g' is 100bucks.
&
By using a C++ Program i want to calculate the overall cost of the order.
Like adding f2+f3+g2=50+50+100
and finally Output=200bucks;
The program should read only the 2nd line(coz thats where the food codes are entered)
Pls respond as soon as possible.
Thank You
Last edited on
Well, being a beginner myself, I can tell you this much
1
2
3
   ifstream file;
file.open ("*.txt");
file >> variable; 

That is how you get data from a file (replace variable with the name of a variable in your program and * with the name of a .txt file.)
You need to include the <fstream> library for it work.

About the calculations
Just declare a new variable and use
1
2
variableC=variableA+variableB;
cout << variableC << endl;


I don't know about the second line thing though sorry.
Last edited on
Thank you,
well i found how to read only the second line and i'll try ur idea , i guess it would work.
Topic archived. No new replies allowed.