There is an error when i try to compile and im not sure whats wrong with it.
This is a program which authencate username and password with textfile, seperated with “;” delimeter in a single textfile.
The error is quite long.
/tmp/ccgs7RYV.o: In function 'Employee::Employee()': main2.cpp:(.text+0xa5): undefined reference to 'Employee::authenticate(std::basic_string, std::allocator>, std::basic_string, std::allocator>)' /tmp/ccgs7RYV.o: In function `Employee::Employee()': main2.cpp:(.text+0x231): undefined reference to 'Employee::authenticate(std::basic_string, std::allocator>, std::basic_string, std::allocator>)' collect2: ld returned 1 exit status
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
class Employee
{
public:
Employee();
bool authenticate(string, string);
};
Employee::Employee()
{
string username, password;
cout << "Username: ";
cin >> username;
cout << "Password: ";
cin >> password;
if (authenticate(username, password) == true)
cout << "Sucess" << endl;
else
cout << "fail" << endl;
}
bool authenticate(string username, string password)
{
std::ifstream file("login.txt");
std::string fusername, fpassword;
while (!file.fail())
{
std::getline(file, fusername, ';'); // use ; as delimiter
std::getline(file, fpassword); // use line end as delimiter
// remember - delimiter readed from input but not added to output
if (fusername == username && fpassword == password)
return true;
}
return false;
}
int main()
{
Employee();
return 0;
}
You need to use the scope resolution operator. You were just missing that.