无法识别C++的多个函数

C++ Multiple Functions Not Recognized

本文关键字:函数 C++ 识别      更新时间:2023-10-16

这可能是一个非常简单的错误,但我创建了一个名为longin_page()的函数;

int login_page(string username,string password) {

无论如何,这是函数头,函数很长。然而,当我调用另一个文件中的函数(该函数被定义和引用到该文件)时,它似乎无法识别我定义的两个参数。

else if (input1 == "login") {
    get_user_info();
    login_page(file_username, file_password);
}

在VisualStudio中,我收到一个错误,说函数不接受两个参数。万一你想查看我的所有文件,它们都发布在下面。

login_page.cpp:

#include <iostream>
#include <Windows.h>
#include "login_page.h"
#include <string>
#include <fstream>
#include "profile_main_menu.h"using namespace std;
string file_username, file_password;
int get_user_info() {
ifstream user_info;
user_info.open("user_info.txt");
if (user_info.is_open()) {
    user_info >> file_username;
    user_info >> file_password;
    cout << "File open" << endl;
    cout << file_username << endl;
    cout << file_password;
}
else {
    cout << "Could not get info fro user_info.txt" << endl;
}
return 0;
}
int login_page(string username,string password) {
string username_input_2;
string password_input_2;
ifstream user_info;
user_info.open("user_info.txt");
string file_username, file_password;
if (user_info.is_open()) {
    get_user_info();
}
else {
    cout << "Error: No username and/or password found on user_info.txt" << endl;
    login_page();
}
cout << "Please enter your username: " << endl;
cin >> username_input_2;
if (username == username_input_2) {
    cout << username_input_2 << " , please enter your password." << endl;
    cin >> password_input_2;
    if (password == file_password) {
        profile_main_menu();
    }
    else {
        cout << "Passwords do not match. Please try again." << endl;
        login_page();
    }
}
else {
    cout << "You do not have an account or you have misspeld your username. Please try again." << endl;
    cout << username_input_2 << endl;
    cout << username << endl;
    login_page();
}
return 0;

}

login_page.h:

#define LOGIN_PAGE_H
int login_page();
int get_user_info();

initial_page_funct.cpp:(这是我得到错误的地方)

#include <iostream>
#include <string>
#include <Windows.h>
#include "login_page.h"
#include "create_account.h"
using namespace std;
extern string file_username, file_password;
int initial_login() {
string input1;
cout << "Welcome to AgentOS V230.20043." << endl;
Sleep(3000);
cout << "If you do not have an account and wish to create one, enter "create account"" << endl;
Sleep(3000);
cout << "If you do have an account, enter "login"" << endl;
getline(cin, input1);
if (input1 == "create account") {
    create_account();
}
else if (input1 == "login") {
    get_user_info();
    login_page(file_username, file_password);
}
else {
    cout << "You have not entered a knowned command. Please try again." << endl;
    cout << "This is the command: " << input1 << endl;
    initial_login();
}
return 0;

}

标头中的函数声明不正确。在login_page.h中替换

int login_page();

带有:

int login_page(string username,string password);