Hello, i would like to ask about how to create search in file handling because whenever i try mine it always have this error of unable to open the file even though the .txt exists.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
FILE *fp;
fp = fopen("list.txt", "a+");
if (!fp)
{
cout << "Cannot open file. \n";
exit(1);
}
struct Sample
{
char fname[255];
char lname[255];
char eno[30];
char salary[30];
};
struct Sample e;
int a;
cout << "Enter 1 or 2 for choices \n";
cout << "[1] ADD AN EMPLOYEE \n";
cout << "[2] LIST ALL EMPLOYEE \n";
cout << "[3] DELETE AN EMPLOYEE \n";
cout << "[4] SEARCH AN EMPLOYEE \n";
cout << "your answer: ";
cin >> a;