<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 循环直到按下某个键,例如退出?

      C++: execute a while loop until a key is pressed e.g. Esc?(C++:执行 while 循环直到按下某个键,例如退出?)
        <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 循环直到按下某个键,例如退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)
                <legend id='FsXzy'><style id='FsXzy'><dir id='FsXzy'><q id='FsXzy'></q></dir></style></legend>

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

                      • <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>
                          <tbody id='FsXzy'></tbody>
                        <tfoot id='FsXzy'></tfoot>
                        • <bdo id='FsXzy'></bdo><ul id='FsXzy'></ul>