Reading 2nd line and selecting particular letters(txt file)!!

Jan 13, 2014 at 4:31pm
My text file contains two lines:-

Tableno:1
s1,t2


Question:-
How to read only the 2nd line "s1,t2".
And in that i want only the letters (s and t) to be selected and it should be assigned its values (for eg:50 & 75).

My aim:-
To calculate the bill using the food codes(s1 and t2).


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Restaurant Manager Table-2
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;

class table{
      public:
      
          void menu()
                 { 
                    ifstream menu;
                    menu.open("menu.txt");
                    string STRING;
                    string inFile_contents;
                    string previousLine="";
                    while(!menu.eof())
                     {
                       getline(menu,STRING); // Saves the line in STRING.
                       if (STRING != previousLine)
                       {
                         previousLine=STRING;
                         cout<<STRING<<endl; // Prints our STRING.
                       }
                     }
                    menu.close();
                 }
     
          void order()
               {int tno=2;
                char ordr[100];
                cout<<"\n\nPlease enter the food codes\n";
                cout<<"(Eg:like f2,d1,c3)\n";
                ofstream outfile;
                outfile.open("Order2.txt");
                cin.getline(ordr,100);
                outfile <<"TableNo: "<< tno <<endl << ordr <<endl;
                outfile.close();
                cout<<".";
                Sleep(800);
                cout<<".";
                Sleep(800);
                cout<<".";
                Sleep(1000);
                cout<<"Your order has been placed\n";
               }
           }c;
int main()
{   char x;
    c.menu(); 
    c.order();
    getch();
}
     


I use DevC++, the above codes are compiled and has no errors.
Jan 13, 2014 at 6:08pm
It looks like a good start; however, you need to read each line into its own variable.
Last edited on Jan 13, 2014 at 6:10pm
Jan 14, 2014 at 3:34am
May i pls have its code ??
Jan 14, 2014 at 6:46am
What?
Jan 14, 2014 at 5:21pm
You read a line of data into your variable "ordr" on line 37. That is the first line in your input file.

Read the next line into your other variables.
Jan 15, 2014 at 5:11am
K thank u kooth
it was helpful!! :)
Jan 15, 2014 at 6:13pm
I'm glad I was helpful! Please mark this as solved so that it might help others.
Topic archived. No new replies allowed.