Я делаю небольшой проект по изучению C++ и веб-технологий. Я работаю на Python, поэтому не совсем понимаю, что этот исходный код нужно сначала собрать, а затем превратить в .exe, пока, так что извините, если это глупая ошибка новичка.
Вот функция на моем сервере:
Я делаю небольшой проект по изучению C++ и веб-технологий. Я работаю на Python, поэтому не совсем понимаю, что этот исходный код нужно сначала собрать, а затем превратить в .exe, пока, так что извините, если это глупая ошибка новичка. Вот функция на моем сервере: [code]// generate maze app.get('/api/generate-maze', (req, res) => {
const width = 11; // TODO: get data from front end const height = 11; const startX = 1; const startY = 1; const endX = 9; const endY = 9;
// Run C++ program const cppProcess = spawn('../cpp/maze_generator.exe', [width, height, startX, startY, endX, endY])
// When the C++ program finishes: cppProcess.on('close', (code) => { // Read the JSON file C++ created const mazeData = fs.readFileSync('public/data/maze.json');
// Send it to browser res.json(JSON.parse(mazeData)); });
// Handle errors cppProcess.on('error', (err) => { res.status(500).json({ error: 'C++ program failed' }); }); }); [/code] а это C++: [code]#include #include #include #include #include #include
class MazeGenerator { private: // member variables int width, height; std::vector maze; std::mt19937 rng;
public: MazeGenerator(int w, int h) : width(w), height(h), rng(std::time(nullptr)) { // constructor (like def __init__()) // This means: // width = w; (set width to the w parameter) // height = h; (set height to the h parameter) // rng = std::time(nullptr); (seed random generator with current time)
// Then run the constructor body: maze = std::vector(height, std::vector(width, 1)); // height x width matrix containing 1s }
void generateMaze(std::pair start = {1,1}, std::pair end = {-1,-1}) {
// If end is {-1,-1}, calculate the real end if (end.first == -1) { end = {height-2, width-2}; // bottom-right corner }