<legend id='QvyFZ'><style id='QvyFZ'><dir id='QvyFZ'><q id='QvyFZ'></q></dir></style></legend>

    <small id='QvyFZ'></small><noframes id='QvyFZ'>

      • <bdo id='QvyFZ'></bdo><ul id='QvyFZ'></ul>
    1. <tfoot id='QvyFZ'></tfoot>

      <i id='QvyFZ'><tr id='QvyFZ'><dt id='QvyFZ'><q id='QvyFZ'><span id='QvyFZ'><b id='QvyFZ'><form id='QvyFZ'><ins id='QvyFZ'></ins><ul id='QvyFZ'></ul><sub id='QvyFZ'></sub></form><legend id='QvyFZ'></legend><bdo id='QvyFZ'><pre id='QvyFZ'><center id='QvyFZ'></center></pre></bdo></b><th id='QvyFZ'></th></span></q></dt></tr></i><div id='QvyFZ'><tfoot id='QvyFZ'></tfoot><dl id='QvyFZ'><fieldset id='QvyFZ'></fieldset></dl></div>

      C++:执行 while 循环直到按下某个键,例如退出?

      时间:2023-08-27
        <tfoot id='trhWS'></tfoot>
        <legend id='trhWS'><style id='trhWS'><dir id='trhWS'><q id='trhWS'></q></dir></style></legend>
        <i id='trhWS'><tr id='trhWS'><dt id='trhWS'><q id='trhWS'><span id='trhWS'><b id='trhWS'><form id='trhWS'><ins id='trhWS'></ins><ul id='trhWS'></ul><sub id='trhWS'></sub></form><legend id='trhWS'></legend><bdo id='trhWS'><pre id='trhWS'><center id='trhWS'></center></pre></bdo></b><th id='trhWS'></th></span></q></dt></tr></i><div id='trhWS'><tfoot id='trhWS'></tfoot><dl id='trhWS'><fieldset id='trhWS'></fieldset></dl></div>

          <bdo id='trhWS'></bdo><ul id='trhWS'></ul>

        • <small id='trhWS'></small><noframes id='trhWS'>

              <tbody id='trhWS'></tbody>
              1. 本文介绍了C++:执行 while 循环直到按下某个键,例如退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有人有一段代码不使用 windows.h 来检查 while 循环中的按键.基本上是这段代码,但不必使用 windows.h 来做到这一点.我想在 Linux 和 Windows 上使用它.

                Does anyone have a snippet of code that doesn't use windows.h to check for a key press within a while loop. Basically this code but without having to use windows.h to do it. I want to use it on Linux and Windows.

                #include <windows.h>
                #include <iostream>
                
                int main()
                {
                    bool exit = false;
                
                    while(exit == false)
                    {
                        if (GetAsyncKeyState(VK_ESCAPE))
                        {
                            exit = true;
                        }
                        std::cout<<"press esc to exit! "<<std::endl;
                    }
                
                    std::cout<<"exited: "<<std::endl;
                
                    return 0;
                }
                

                推荐答案

                最好的办法是创建一个自定义的GetAsyncKeyState"函数,该函数将使用 #IFDEF 为 windows 和 linux 选择合适的 GetAsyncKeyState() 或等效函数.

                Your best bet is to create a custom "GetAsyncKeyState" function that will use #IFDEF for windows and linux to choose the appropriate GetAsyncKeyState() or equivalent.

                >

                没有其他方法可以达到预期的结果,cin 方法有其问题 - 例如应用程序必须处于焦点.

                No other way exists to achieve the desired result, the cin approach has its problems - such as the application must be in focus.

                这篇关于C++:执行 while 循环直到按下某个键,例如退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:将整行整数读入向量 下一篇:在 C++ 中使用 while 循环读取文件是如何工作的?

                相关文章

                <legend id='FsXzy'><style id='FsXzy'><dir id='FsXzy'><q id='FsXzy'></q></dir></style></legend>

                1. <small id='FsXzy'></small><noframes id='FsXzy'>

                  1. <i id='FsXzy'><tr id='FsXzy'><dt id='FsXzy'><q id='FsXzy'><span id='FsXzy'><b id='FsXzy'><form id='FsXzy'><ins id='FsXzy'></ins><ul id='FsXzy'></ul><sub id='FsXzy'></sub></form><legend id='FsXzy'></legend><bdo id='FsXzy'><pre id='FsXzy'><center id='FsXzy'></center></pre></bdo></b><th id='FsXzy'></th></span></q></dt></tr></i><div id='FsXzy'><tfoot id='FsXzy'></tfoot><dl id='FsXzy'><fieldset id='FsXzy'></fieldset></dl></div>
                    <tfoot id='FsXzy'></tfoot>
                    • <bdo id='FsXzy'></bdo><ul id='FsXzy'></ul>