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

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

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

      C++同时输入输出到控制台窗口

      C++ Input and output to the console window at the same time(C++同时输入输出到控制台窗口)
    1. <legend id='viBdw'><style id='viBdw'><dir id='viBdw'><q id='viBdw'></q></dir></style></legend>
        • <bdo id='viBdw'></bdo><ul id='viBdw'></ul>
            <tbody id='viBdw'></tbody>

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

          • <tfoot id='viBdw'></tfoot>

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

              1. 本文介绍了C++同时输入输出到控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个服务器(主要用于 Windows,但如果我可以保持多平台状态会很酷)并且我只使用一个普通的控制台窗口.但是,我希望服务器能够执行诸如 say text_to_say_here 或 kick playername 等命令.我怎样才能有异步输入/输出?我已经用普通的 printf() 和 gets_s 尝试了一些东西,但这导致了一些非常......奇怪的东西.

                I'm writing a server(mainly for windows, but it would be cool if i could keep it multiplatform) and i just use a normal console window for it. However, I want the server to be able to do commands like say text_to_say_here or kick playername, etc. How can i have a asynchronous input/output? I allready tried some stuff with the normal printf() and gets_s but that resulted in some really.... weird stuff.

                我的意思是这样的1

                谢谢.

                推荐答案

                利用 C++11 特性(即跨平台)的快速代码

                Quick code to take advantage of C++11 features (i.e. cross-platform)

                #include <atomic>
                #include <thread>
                #include <iostream>
                
                void ReadCin(std::atomic<bool>& run)
                {
                    std::string buffer;
                
                    while (run.load())
                    {
                        std::cin >> buffer;
                        if (buffer == "Quit")
                        {
                            run.store(false);
                        }
                    }
                }
                
                int main()
                {
                    std::atomic<bool> run(true);
                    std::thread cinThread(ReadCin, std::ref(run));
                
                    while (run.load())
                    {
                        // main loop
                    }
                
                    run.store(false);
                    cinThread.join();
                
                    return 0;
                }
                

                这篇关于C++同时输入输出到控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  <tbody id='5DCBd'></tbody>

                <small id='5DCBd'></small><noframes id='5DCBd'>

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