久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

      • <bdo id='aPGOQ'></bdo><ul id='aPGOQ'></ul>

        <legend id='aPGOQ'><style id='aPGOQ'><dir id='aPGOQ'><q id='aPGOQ'></q></dir></style></legend>
      1. 測(cè)試 stdin 是否有 C++ 輸入(windows 和/或 linux)

        Test if stdin has input for C++ (windows and/or linux)(測(cè)試 stdin 是否有 C++ 輸入(windows 和/或 linux))
      2. <tfoot id='G7DeL'></tfoot>

            <i id='G7DeL'><tr id='G7DeL'><dt id='G7DeL'><q id='G7DeL'><span id='G7DeL'><b id='G7DeL'><form id='G7DeL'><ins id='G7DeL'></ins><ul id='G7DeL'></ul><sub id='G7DeL'></sub></form><legend id='G7DeL'></legend><bdo id='G7DeL'><pre id='G7DeL'><center id='G7DeL'></center></pre></bdo></b><th id='G7DeL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G7DeL'><tfoot id='G7DeL'></tfoot><dl id='G7DeL'><fieldset id='G7DeL'></fieldset></dl></div>
              <tbody id='G7DeL'></tbody>
            1. <small id='G7DeL'></small><noframes id='G7DeL'>

              <legend id='G7DeL'><style id='G7DeL'><dir id='G7DeL'><q id='G7DeL'></q></dir></style></legend>
                  <bdo id='G7DeL'></bdo><ul id='G7DeL'></ul>
                  本文介紹了測(cè)試 stdin 是否有 C++ 輸入(windows 和/或 linux)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我基本上想測(cè)試 stdin 是否有輸入(就像你回聲和管道輸入一樣).我找到了有效的解決方案,但它們很丑陋,我喜歡我的解決方案干凈.

                  I basically want to test if stdin has input (like if you echo and pipe it). I have found solutions that work, but they are ugly, and I like my solutions to be clean.

                  在 linux 上我使用這個(gè):

                  On linux I use this:

                  bool StdinOpen() {
                    FILE* handle = popen("test -p /dev/stdin", "r");
                    return pclose(handle) == 0;
                  }
                  

                  我知道我應(yīng)該添加更多的錯(cuò)誤處理,但這不是重點(diǎn).

                  I know that I should add more error handling, but it's besides the point.

                  在 Windows 上我使用這個(gè):

                  On windows I use this:

                  bool StdinOpen() {
                    static HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
                    DWORD bytes_left;
                    PeekNamedPipe(handle, NULL, 0, NULL, &bytes_left, NULL);
                    return bytes_left;
                  }
                  

                  這對(duì) linux 來說很好,但我想知道我可以在不使用管道的情況下調(diào)用的等效 API 是什么(例如對(duì)于 test -f $file,您執(zhí)行 fopen($文件,"r") != NULL).我有一種暗示,我可以 open("/dev/stdin", "r") 并做同樣的事情,但我想知道最好的方法.

                  That is fine for linux, but I want to know what are the equivalent APIs that I can call without using a pipe (like for test -f $file you do fopen($file, "r") != NULL). I have an inkling that I could open("/dev/stdin", "r") and do the same thing, but I want to know the best way to do it.

                  總結(jié):我想知道我可以用來代替 Linux 的 test -p/dev/stdin 的 API,如果你知道更好的解決方案窗戶.

                  Summary: I want to know the APIs I could use to substitute for test -p /dev/stdin for linux, and, if you know a better solution for windows.

                  推薦答案

                  這是 POSIX (Linux) 的解決方案:我不確定 Windows 上的 poll() 等價(jià)物是什么.在 Unix 上,編號(hào)為 0 的文件描述符是標(biāo)準(zhǔn)輸入.

                  Here's a solution for POSIX (Linux): I'm not sure what's the equivalent of poll() on Windows. On Unix, The file descriptor with number 0 is the standard input.

                  #include <stdio.h>
                  #include <sys/poll.h>
                  
                  int main(void)
                  {
                          struct pollfd fds;
                          int ret;
                          fds.fd = 0; /* this is STDIN */
                          fds.events = POLLIN;
                          ret = poll(&fds, 1, 0);
                          if(ret == 1)
                                  printf("Yep
                  ");
                          else if(ret == 0)
                                  printf("No
                  ");
                          else
                                  printf("Error
                  ");
                          return 0;
                  }
                  

                  測(cè)試:

                  $ ./stdin
                  No
                  $ echo "foo" | ./stdin
                  Yep
                  

                  這篇關(guān)于測(cè)試 stdin 是否有 C++ 輸入(windows 和/或 linux)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                  When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對(duì)象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區(qū)別)
                  • <bdo id='K2XSt'></bdo><ul id='K2XSt'></ul>

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

                      <tbody id='K2XSt'></tbody>

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

                          • <legend id='K2XSt'><style id='K2XSt'><dir id='K2XSt'><q id='K2XSt'></q></dir></style></legend>
                            主站蜘蛛池模板: av中文字幕在线观看 | 美女久久久久 | 久久久精品综合 | 欧美日韩久| 国产精品揄拍一区二区久久国内亚洲精 | 一区二区三区在线观看视频 | 99看片网| 中文字幕亚洲专区 | 欧美精品一二三区 | 亚洲国产精品一区二区久久 | va在线 | 影视先锋av资源噜噜 | 亚洲成人av | 久久精品视频播放 | 一区二区在线 | 欧美综合色 | 中文字幕日韩欧美一区二区三区 | 午夜影院官网 | 97在线观视频免费观看 | 国产精品欧美一区二区三区 | 国产一级免费视频 | 亚洲网站在线观看 | 国产精品亚洲一区 | 夜久久 | 亚洲美女在线一区 | a在线免费观看 | 美女天天操| 午夜欧美 | 久久免费视频1 | 麻豆视频在线免费看 | 成人网av | 国产一区91精品张津瑜 | 夜夜艹| 亚洲精品成人免费 | 男人av在线播放 | 日本精品视频在线 | 男女视频在线观看 | 精品免费看 | 日韩av在线一区二区 | 国产一区二区三区色淫影院 | 又黑又粗又长的欧美一区 |