我有一个头文件BookStore.header,我创建了一个带有私有属性的类Users:
int id_user;
char* u_name;
char* email;
char password[20];
static unsigned int nr_user;
getter,setter,constructors,析构函数和
User(const User&);
User &operator=(const User&);
friend istream &operator>> (istream &, User&);
friend ostream &operator<< (ostream &, User);
bool isLogIn();
bool userexist(ifstream& , User& );
int get_users_count(ifstream &);
然后我创建了一个BookStore.cpp,其中包含#include"BookStore.h"
并实现了所有方法,构造函数+
bool User::isLogIn(){
string username, password, file_line;
cout << "enter username:";
cin >> username;
cout << "enter pass:";
cin >> password;
ifstream infile;
infile.open("users.txt");
if (!infile.is_open()){
cout << "Error while opening the file...";
}
else{
string str;
while (getline(infile, str)){
vector<string> newVector = split(str);
/*for (string line; getline(infile, line);)
{*/
string username_from_file = newVector[1];
string password_from_file = newVector[3];
if ((username_from_file.compare(username) == 0) && (password_from_file.compare(password)) == 0){
return true;
}
/*}*/
}
}
return false;
/* if (un == username&& pw == password){
return true;
}
else
return false;
}*/
}
bool userexist(ifstream& file, User& u){
string str;
while (getline(file, str)){
vector<string> newVector = split(str);
cout << newVector.size();
if (newVector.size() > 0){
string username_from_file = newVector[1];
if ((username_from_file.compare(u.getName()) == 0)){
file.close();
return true;
}
}
}
file.close();
return false;
}
int get_users_count(ifstream &file){
string str;
int i = 0;
while (getline(file, str)){
vector<string> newVector = split(str);
if (newVector.size() > 0){
string iduser = newVector[0];
i++;
}
}
file.close();
return i;
}
我的问题出在主要课程中,其中包括&#34; BookStore.h&#34;
{
cin >> u5;
ifstream infile;
infile.open("users.txt");
if (!userexist(infile, u5)){
infile.open("users.txt");
int numbers_ids = get_users_count(infile);
u5.set_id(&numbers_ids);
outFile << u5.get_id() << " " << u5.getName() << " " << u5.getEmail() << " " << u5.getPass() << " " << endl;
//outFile << u5;
cout << "Registration succesfull!";
cout << endl;
outFile.close();
}
当我跑步时,我得到了 1智能感知:标识符&#34; userexist&#34;未定义的 2 IntelliSense:标识符&#34; get_users_count&#34;未定义