gpt4 book ai didi

c++ - 搜索 vector 时出错?

转载 作者:行者123 更新时间:2023-11-28 02:56:50 25 4
gpt4 key购买 nike

标题

#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。

最佳答案

您的 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());
}

关于c++ - 搜索 vector 时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21789020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com