Reading a txt file

Guys, can you help me in this problem:
A cpp program that reads a text file named "employee.txt", which contains:

EMPO1, Juan, 1
EMPO2, Pedro, 2

The program requires enter the code and compares the code to the existing file "employee.txt". When if the code is found, it prints the name, level and salary associated with the code on the console. Then it prints the code and the salary on the file "record.txt"

Specs:

EMPO1 = code
Juan = name
1 = level

Salary:
level 1 = 200 pesos
level 2 = 250 pesos

Sample output:

Enter Code: EMPO1(entered by the user)

Name: Juan
Level: 1
Salary: 200 pesos.

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
#include <iostream>
#include <fstream>
using namespace std;
class level{
public:
    int lvl1;
    int lvl2;
private:
    void set_lvl1(int a){
        lvl1=200;
    }
    void set_lvl2(int b){
        lvl1=250;
    }

};
int main () {
  ifstream ER;
  string line, emp_code, name, lvl;
  ER.open("employee.txt");
  if (ER.is_open())
  {
       while ( ER.good() )
    {
      getline (ER,line);
      cout << line <<endl;
    }
    ER.close();
  }
  ios::beg;

  cout<<"Enter Code: ";
  getline(cin, emp_code);


  cout<<"Name: "<<name<<endl;
  cout<<"Level: "<<lvl<<endl;
  cout<<"Salary: "<<endl;



  return 0;
}

Last edited on
This is quite easy to implement. You just have to sit and think it through. A suggestion is to use getline(ER, line) as your while loop condition -line 23. You also might want to get the code first before searching the file for the code, or am I missing something?
I'm getting difficulty in containing the EMPO1, Name, and Level from the first line...
I don't get the logical expression to contain it.
Topic archived. No new replies allowed.