C ++多功能无法识别

时间:2015-07-01 21:05:33

标签: c++ arguments

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

的函数
int login_page(string username,string password) {

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

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

在Visual Studio中,我收到一条错误消息,指出该函数不带两个参数。如果你想检查我的所有文件,它们会在下面发布。

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;

}

1 个答案:

答案 0 :(得分:2)

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

int login_page();

使用:

int login_page(string username,string password);