<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++同时输入输出到控制台窗口

      时间:2023-06-30
    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++同时输入输出到控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:C++ chrono系统时间以毫秒为单位,时间操作 下一篇:std::chrono::clock,硬件时钟和周期计数

                相关文章

                <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>