在html中执行.exe (c++)或转换为javascript

Executing .exe (c++) in html or converting to javascript

本文关键字:转换 javascript c++ html 执行 exe      更新时间:2023-10-16

是否可以在服务器/网页上运行EXE (c++)并使EXE返回响应,或者我必须将此EXE (c++)转换为javascript?

如果我必须将代码转换为javascript,我该怎么做?我知道javascript的基础知识,但我不知道如何读写。txt文件。

基本上我的代码是一个登录系统,我想使用我的网站,所以我不必使用mysql或数据库。我知道这是一个缓慢的,可能是一个愚蠢的方法,但这是一个项目。任何帮助都是感激的!

编辑:你按下登录按钮,然后如果你提示与EXE文件,你可以看到上面。然后EXE文件发送回服务器,如果登录成功和信息。EXE文件必须在服务器上,所以客户端不必下载它。

代码:

#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
using namespace std;
void cls() { system("cls"); }
bool mainPage(string &username, string &password) {
    cls();
    cout << "Username: "; getline(cin, username);
    cout << "Password: "; getline(cin, password);
    if(username != "" && password != "") {
        return true;
    }
    else {
        return false;
    }
}
bool checkLogin(string &username, string &password, string &email, string &firstName, string &lastName) {
    string pw = "";
    ifstream ifile(username + ".txt");
    if(ifile.is_open()) {
        ifile >> pw >> email >> firstName >> lastName;
        if(pw == password) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}
bool loginFail() {
    string fail = "";
    string undef = "";
    cls();
    cout << "'reg'" << endl;
    cout << "'main'" << endl;
    getline(cin, fail);
    if(fail == "reg") {
        return true;
    }
    else if(fail == "main") {
        return false;
    }
    else {
        cout << "nCould not understand you." << endl;
        getline(cin, undef);
        return loginFail();
    }
}
bool regist() {
    string un;
    string pw;
    string em;
    string fn;
    string ln;
    string undef = "";
    cls();
    cout << "'main'" << endl;
    cout << "nNew username: "; getline(cin, un);
    cout << "New password: "; getline(cin, pw);
    if((un != "" && pw != "") && (un != "main" && pw != "main")) {
        ifstream ifile(un + ".txt");
        if (ifile.is_open()) {
            cout << "nThis username is already taken." << endl;
            getline(cin, undef);
            return regist();
        }
        else {
            cout << "nEmail: "; getline(cin, em);
            cout << "nFirst name: "; getline(cin, fn);
            cout << "Last name: "; getline(cin, ln);
            if(em != "" && fn != "" && ln != "") {
                ofstream ofile;
                ofile.open(un + ".txt");
                if (ofile.is_open()) {
                    ofile << pw << endl;
                    ofile << em << endl;
                    ofile << fn << endl;
                    ofile << ln << endl;
                    ofile.close();
                    cout << "nFile was successfully written to." << endl;
                    getline(cin, undef);
                    return true;
                }
                else {
                    cout << "nFile could not open." << endl;
                    getline(cin, undef);
                    return regist();
                }
            }
            else {
                cout << "nYou didn't enter one of the above." << endl;
                getline(cin, undef);
                return regist();
            }
        }
    }
    else if(un == "main" || pw == "main") {
        return false;
    }
    else {
        cout << "nYou didn't do it correct." << endl;
        getline(cin, undef);
        return regist();
    }
}
void loginSuccess(string username, string password, string email, string firstName, string lastName) {
    string undef = "";
    cls();
    cout << "You have successfully logged in." << endl;
    cout << "nUsername: " << username << endl;
    cout << "Password: " << password << endl;
    cout << "nEmail: " << email << endl;
    cout << "nFrist name: " << firstName << endl;
    cout << "Last name: " << lastName << endl;
    getline(cin, undef);
}
int main(void) {
    system("color a");
    string username = "";
    string password = "";
    string email = "";
    string firstName = "";
    string lastName = "";
    if(!mainPage(username, password)) {
        return main();
    }
    else {
        if(!checkLogin(username, password, email, firstName, lastName)) {
            if(!loginFail()) {
                return main();
            }
            else {
                if (!regist()) {
                    return main();
                }
                else {
                    return main();
                }
            }
        }
        else {
            loginSuccess(username, password, email, firstName, lastName);
        }
    }
}

你不能在浏览器中使用Javascript编写文件系统。我认为您应该使用客户机-服务器体系结构来编写应用程序。例如,客户机将是一个简单的HTML页面,其中包含用户名和密码的输入,服务器将保存并检查用户的凭据。在这种情况下,您可以使用Javascript将数据从页面发送到服务器。