c++ - .exe 不显示 "Press any key to continue..."

标签 c++

enter image description here 在 Visual Studio 中,每当我在没有调试的情况下启动时,显示的 .exe 文件不像通常那样包含短语“按任意键继续...”。屏幕的开头只有闪烁的光标。有什么简单的解决方法吗?我已经注释掉了我的一些代码,并且该短语重新显示。

这是我注释掉的代码:我正确声明了所有变量和类。

void Maze::addPaths()
{
    Coordinate currentLocation;
    Coordinate startLocation;
    Coordinate endLocation; //not used yet
    std::stack<Coordinate> stack;

    currentLocation.row = (((rand() % HEIGHT) / 2) * 2);
    currentLocation.column = (((rand() % WIDTH) / 2) * 2);

    startLocation = currentLocation;
    grid[currentLocation.row][currentLocation.column] = START;
    player = currentLocation;
    do 
    {
        //drawMaze();
        bool canMoveUp = !(currentLocation.row == 0 || grid[currentLocation.row - 2][currentLocation.column] != WALL);
        bool canMoveDown = !(currentLocation.row == HEIGHT - 1 || grid[currentLocation.row + 2][currentLocation.column] != WALL);
        bool canMoveLeft = !(currentLocation.column == 0 || grid[currentLocation.row][currentLocation.column - 2] != WALL);
        bool canMoveRight = !(currentLocation.column == WIDTH - 1 || grid[currentLocation.row][currentLocation.column + 2] != WALL);

        if (canMoveUp || canMoveDown || canMoveLeft || canMoveRight)
        {
            stack.push(currentLocation);

            //choose random location to dig
            bool moveFound = false;
            while (!moveFound)
            {
                int direction = rand() % 4;
                if (direction == 0 && canMoveUp)
                {
                    moveFound = true;
                    grid[currentLocation.row - 2][currentLocation.column] = PATH;
                    grid[currentLocation.row - 1][currentLocation.column] = PATH;
                    currentLocation.row -= 2;
                }
                else if (direction == 1 && canMoveDown)
                {
                    moveFound = true;
                    grid[currentLocation.row + 2][currentLocation.column] = PATH;
                    grid[currentLocation.row + 1][currentLocation.column] = PATH;
                    currentLocation.row += 2;
                }
                else if (direction == 2 && canMoveLeft)
                {
                    moveFound = true;
                    grid[currentLocation.row][currentLocation.column - 2] = PATH;
                    grid[currentLocation.row][currentLocation.column - 1] = PATH;
                    currentLocation.column -= 2;
                }
                else if (direction == 3 && canMoveRight)
                {
                    moveFound = true;
                    grid[currentLocation.row][currentLocation.column + 2] = PATH;
                    grid[currentLocation.row][currentLocation.column - 2] = PATH;
                    currentLocation.column += 2;
                cout << "yay";
                }
            }
        }
        else if (!stack.empty())
        {
            currentLocation = stack.top();
            stack.pop();
        }
    } while (!stack.empty());
    //addDestinationToGrid();
    cout << "no";
}

最佳答案

在 Windows 上,system("PAUSE"); 将提示用户文本:

Press any key to continue...

关于c++ - .exe 不显示 "Press any key to continue...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34804482/

相关文章:

c++ - 无法编译mysql源码

c++ - 我怎么知道 C++ 编译器是否生成线程安全的静态目标代码?

c++ - ifstream 变量循环不打印任何内容

c++ - 对 GLSL 和 OpenGL 感到困惑

c++ - 推送和弹出操作的混合序列为什么这个序列不可能

c++ - 是否可以使用标准库的查找、开始和结束来编写 in_array 辅助函数?

c++ - 使用其指针从列表中删除项目

c++ - std::chrono 纳秒计时器适用于 MSVC,但不适用于 GCC

c++ - 翻译后顶点缓冲区中的数据会改变吗?

c++ - 为什么pthread_join()返回0而不是我的线程的返回值?