Hi guys!
I have a text file name "Employee.txt"..
The text contains the following:
What I wanted to do right now is I kinda put the data in the text file into a structure that I created so that I can easily access the files when I try to search for something like the name of the employee.Code:Juan_De_La_Cruz,A001,1 Miriam_Bismonte,A002,1 Gloria_Macapagal,A003,3 Manny_Pacquiao,A004,3 Jose_Rizal,A005,2
Here is my code so far and I'm kinda stuck right now because I don't know what to do. Feel free to criticize my code because I'm new in c++ and it will help me improve a lot.
I learned how to code in C++ on youtube by watching thenewboston topics about C++ and a couple of google search.Code:#include <iostream> #include <string> #include <fstream> struct Employees { char EmployeeName[50]; char EmployeeID[10]; int Level; }; int main () { using namespace std; int offset; char EmpCode[20]; string line; cout << "----Payroll System----" << endl; cout << "Enter Employee Code: \n"; cin >> EmpCode; ifstream Employee; Employee.open("employee.txt"); if(Employee.is_open()) { while (!Employee.eof()) { getline(Employee, line); if ((offset = line.find(EmpCode, 0)) != string::npos) cout << line << endl; } Employee.close(); } else cout << "Unable to open this file" << endl; return 0; }
Note: I was actually trying to create a Payroll System so please ignore the part with the cin >> EmpCode.![]()




Reply With Quote