首页 > 解决方案 > ifstream 似乎没有打开外部 exe 进行读写

问题描述

我是一个初学者爱好程序员。

我正在开发一个小程序,该程序将从用户那里获取任何国际象棋位置的 FEN 字符串,将其传递到 Stockfish 国际象棋引擎,并在它完成了寻找移动的魔力后从 exe 中获取移动输出。

问题是,一旦我将 FEN 字符串输入到我编译的程序中,命令行窗口仍然是静态的,并且什么也不输出。当我按下回车键时,只会出现新行,当我输入除空格以外的任何内容时,命令行窗口会关闭。

我尝试打开任务管理器检查输入 FEN 字符串后 Stockfish 是否正在运行,但我在任何地方都找不到它,这一定意味着我的程序一开始就没有打开 Stockfish。

以下代码已经在Windows中使用g++顺利编译,没有发现任何错误信息。

在网上做了一些研究后,我尝试将“Stockfish.exe”更改为“C:....(路径)..\Stockfish.exe”无济于事(也有大量编译错误)。

我错过了什么吗?我必须做什么才能让程序真正打开 Stockfish 并输入 FEN 和 UCI 命令?

非常感谢!

^_^

#include <iostream>
#include <fstream>
#include <cctype>
#include <string>

using namespace std;

int main() {

    cout << "Welcome to the Chess Puzzle Solver 1.0!" << endl;
    cout << "Please enter the FEN string of the position you'd like to solve." << endl;
    cout << "" << endl;
    cout << "Example: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" << endl;
    cout << "[The starting position] ^" << endl;
    cout << "" << endl;

    string userStartingFEN;

    cin >> userStartingFEN;


    // Opening Stockfish to do the main stuff!

    ifstream inFile;
    ofstream outFile;


    inFile.open("Stockfish.exe", ios::in | ios::out);
    outFile.open("Stockfish.exe", ios::in | ios::out);

    string uciCommand1;
    uciCommand1 = "uci";

    string uciCommand2;
    uciCommand2 = "setoption name Threads value 4";

    string uciCommand3;
    uciCommand3 = "setoption name Contempt value 0";

    string uciCommand4;
    uciCommand4 = "setoption name Hash value 64";

    cin >> uciCommand1;
    cin >> uciCommand2;
    cin >> uciCommand3;
    cin >> uciCommand4;

    cout << "I will say this if the parameters were set." << endl;

    // Entering the user's wanted position

    string inputtingFEN;
    inputtingFEN = "position fen ";
    cin >> inputtingFEN >> userStartingFEN;

    string checkMe;
    checkMe = "UCI and Position all set!";
    cout << checkMe << endl;

    inFile.close();
        outFile.close();

    return 0;

}

标签: c++chessfen

解决方案


推荐阅读