标题
#ifndef BBOARD_H
#define BBOARD_H
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class User{
};
class Message{
};
class BBoard{
private:
string title;
vector<User> user_list;
User current_user;
vector<Message> message_list;
public:
BBoard();
BBoard(const string &ttl);
void setup(const string &input_file);
void login();
void run();
private:
bool user_exists(const string &name, const string &pass) const;
};
#endif
.cpp文件
#include "BBoard.h"
#include <fstream>
#include <algorithm>
using namespace std;
User user_l;
BBoard::BBoard(){
title = "Hello World";
vector<User> user_list;
User current_user;
vector<Message> message_list;
}
BBoard::BBoard(const string &ttl){
title = ttl;
}
void BBoard::setup(const string &input_file){
ifstream fin;
fin.open("users1.txt");
while(!fin.eof()){
user_list.push_back(user_l);
}
}
bool BBoard::user_exists(const string &name, const string &pass) const{
vector<User>::iterator i = find(user_list.begin(), user_list.end(), name);
}
void BBoard::login(){
string sn, pw;
cout << "Welcome to " << title << endl;
bookmark:
cout << "Enter our username ('Q' or 'q' to quit): ";
getline(cin, sn);
cout << "Enter your password: ('Q' or 'q' to quit): ";
getline(cin, pw);
}
我的user_exists函数不断给出关于没有合适的用户定义转换的错误。我试图使用user_exists来检查用户名和密码,如果它存在,它将返回true。
答案 0 :(得分:2)
您的user_exists
函数为bool
,但不返回任何值。这是一个建议:
bool BBoard::user_exists(const string &name, const string &pass) const{
vector<User>::const_iterator i = find(user_list.begin(), user_list.end(), name);
return !(i == user_list.end());
}