Reading from a file and outputting only certain things.

Hello, I am trying to read in from a file named"parking.txt", and I want to read certain values from this file and output them to the screen. How can this be done? Can this be done?

The values in parking.txt is:

total 5
One 400
Five 300
Ten 200
Twenty 50
Quarter 500

In my code I would like to replace "line" with the appropriate value from the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
   ifstream inputFile ("parking_account.txt");
   string line;

   getline(inputFile, line);
 
   cout <<"\n\t-------------------------------------------------------";
   cout <<"\n\t=======================================================";
   cout <<"\n\t              Parking Machine Accounts                 ";
   cout <<"\n\t=======================================================";
   cout <<"\n\tSr. No.  : Bill Name       :  Bill Count  :  Cost(in$) ";
   cout <<"\n\t-------------------------------------------------------";
   cout <<"\n\t       1 : One Dollar      :  " << line << "  :  ";
   cout <<"\n\t       2 : Five Dollar     :  " << line << "  :  ";
   cout <<"\n\t       3 : Ten Dollar      :  " << line << "  :  ";
   cout <<"\n\t       4 : Twenty Dollar   :  " << line << "  :  ";
   cout <<"\n\t       5 : Quarter         :  " << line << "  :  ";

   cout<<"\n\tTotal bill types found : " <<line <<endl;

}


I have tried a while loop that searches line by line, but it outputs 5 of the same menus with line updated for that text value. Here is the while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
nt main()
{
   ifstream inputFile ("parking_account.txt");
   string line;

   getline(inputFile, line);
while (inputFile)
{
   cout <<"\n\t-------------------------------------------------------";
   cout <<"\n\t=======================================================";
   cout <<"\n\t              Parking Machine Accounts                 ";
   cout <<"\n\t=======================================================";
   cout <<"\n\tSr. No.  : Bill Name       :  Bill Count  :  Cost(in$) ";
   cout <<"\n\t-------------------------------------------------------";
   cout <<"\n\t       1 : One Dollar      :  " << line << "  :  ";
   cout <<"\n\t       2 : Five Dollar     :  " << line << "  :  ";
   cout <<"\n\t       3 : Ten Dollar      :  " << line << "  :  ";
   cout <<"\n\t       4 : Twenty Dollar   :  " << line << "  :  ";
   cout <<"\n\t       5 : Quarter         :  " << line << "  :  ";

   cout<<"\n\tTotal bill types found : " <<line <<endl;
   getline(inputFile, line);
}
}
Topic archived. No new replies allowed.