锘??xml version="1.0" encoding="utf-8" standalone="yes"?>99国产精品久久,成人a毛片久久免费播放,久久国产色av免费看http://www.shnenglu.com/kenwell/category/1166.html鑷繁瀛︿範(fàn)鎵鐢?/description>zh-cnTue, 03 Aug 2010 11:00:44 GMTTue, 03 Aug 2010 11:00:44 GMT60Windows Socket浜旂I/O妯″瀷鈥斺斾唬鐮佸叏鏀葷暐錛堜笅錛?/title><link>http://www.shnenglu.com/kenwell/archive/2010/08/03/122086.html</link><dc:creator>c++ 瀛︿範(fàn)</dc:creator><author>c++ 瀛︿範(fàn)</author><pubDate>Tue, 03 Aug 2010 09:27:00 GMT</pubDate><guid>http://www.shnenglu.com/kenwell/archive/2010/08/03/122086.html</guid><wfw:comment>http://www.shnenglu.com/kenwell/comments/122086.html</wfw:comment><comments>http://www.shnenglu.com/kenwell/archive/2010/08/03/122086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/kenwell/comments/commentRss/122086.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/kenwell/services/trackbacks/122086.html</trackback:ping><description><![CDATA[<p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">2.鐢ㄥ畬鎴愪緥紼嬫柟寮忓疄鐜扮殑閲嶅彔I(yíng)/O妯″瀷<br style="line-height: normal; ">#include <WINSOCK2.H><br style="line-height: normal; ">#include <stdio.h></p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#define PORT    5150<br style="line-height: normal; ">#define MSGSIZE 1024</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#pragma comment(lib, "ws2_32.lib")</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef struct<br style="line-height: normal; ">{<br style="line-height: normal; ">WSAOVERLAPPED overlap;<br style="line-height: normal; ">WSABUF        Buffer;<br style="line-height: normal; ">char          szMessage[MSGSIZE];<br style="line-height: normal; ">DWORD         NumberOfBytesRecvd;<br style="line-height: normal; ">DWORD         Flags; <br style="line-height: normal; ">SOCKET        sClient;<br style="line-height: normal; ">}PER_IO_OPERATION_DATA, *LPPER_IO_OPERATION_DATA;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID);<br style="line-height: normal; ">void CALLBACK CompletionROUTINE(DWORD, DWORD, LPWSAOVERLAPPED, DWORD);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">SOCKET g_sNewClientConnection;<br style="line-height: normal; ">BOOL   g_bNewConnectionArrived = FALSE;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">int main()<br style="line-height: normal; ">{<br style="line-height: normal; ">WSADATA     wsaData;<br style="line-height: normal; ">SOCKET      sListen;<br style="line-height: normal; ">SOCKADDR_IN local, client;<br style="line-height: normal; ">DWORD       dwThreadId;<br style="line-height: normal; ">int         iaddrSize = sizeof(SOCKADDR_IN);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Initialize Windows Socket library<br style="line-height: normal; ">WSAStartup(0x0202, &wsaData);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create listening socket<br style="line-height: normal; ">sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Bind<br style="line-height: normal; ">local.sin_addr.S_un.S_addr = htonl(INADDR_ANY);<br style="line-height: normal; ">local.sin_family = AF_INET;<br style="line-height: normal; ">local.sin_port = htons(PORT);<br style="line-height: normal; ">bind(sListen, (struct sockaddr *)&local, sizeof(SOCKADDR_IN));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Listen<br style="line-height: normal; ">listen(sListen, 3);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create worker thread<br style="line-height: normal; ">CreateThread(NULL, 0, WorkerThread, NULL, 0, &dwThreadId);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Accept a connection<br style="line-height: normal; ">    g_sNewClientConnection = accept(sListen, (struct sockaddr *)&client, &iaddrSize);<br style="line-height: normal; ">    g_bNewConnectionArrived = TRUE;<br style="line-height: normal; ">    printf("Accepted client:%s:%d\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));<br style="line-height: normal; ">}<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID lpParam)<br style="line-height: normal; ">{<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    if (g_bNewConnectionArrived)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      // Launch an asynchronous operation for new arrived connection<br style="line-height: normal; ">      lpPerIOData = (LPPER_IO_OPERATION_DATA)HeapAlloc(<br style="line-height: normal; ">        GetProcessHeap(),<br style="line-height: normal; ">        HEAP_ZERO_MEMORY,<br style="line-height: normal; ">        sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">      lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">      lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">      lpPerIOData->sClient = g_sNewClientConnection;<br style="line-height: normal; ">      <br style="line-height: normal; ">      WSARecv(lpPerIOData->sClient,<br style="line-height: normal; ">        &lpPerIOData->Buffer,<br style="line-height: normal; ">        1,<br style="line-height: normal; ">        &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">        &lpPerIOData->Flags,<br style="line-height: normal; ">        &lpPerIOData->overlap,<br style="line-height: normal; ">        CompletionROUTINE);      <br style="line-height: normal; ">      <br style="line-height: normal; ">      g_bNewConnectionArrived = FALSE;<br style="line-height: normal; ">    }</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    SleepEx(1000, TRUE);<br style="line-height: normal; ">}<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">void CALLBACK CompletionROUTINE(DWORD dwError,<br style="line-height: normal; ">                                DWORD cbTransferred,<br style="line-height: normal; ">                                LPWSAOVERLAPPED lpOverlapped,<br style="line-height: normal; ">                                DWORD dwFlags)<br style="line-height: normal; ">{<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = (LPPER_IO_OPERATION_DATA)lpOverlapped;<br style="line-height: normal; "><br style="line-height: normal; ">if (dwError != 0 || cbTransferred == 0)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Connection was closed by client<br style="line-height: normal; ">closesocket(lpPerIOData->sClient);<br style="line-height: normal; ">HeapFree(GetProcessHeap(), 0, lpPerIOData);<br style="line-height: normal; ">}<br style="line-height: normal; ">else<br style="line-height: normal; ">{<br style="line-height: normal; ">    lpPerIOData->szMessage[cbTransferred] = '\0';<br style="line-height: normal; ">    send(lpPerIOData->sClient, lpPerIOData->szMessage, cbTransferred, 0);<br style="line-height: normal; ">    <br style="line-height: normal; ">    // Launch another asynchronous operation<br style="line-height: normal; ">    memset(&lpPerIOData->overlap, 0, sizeof(WSAOVERLAPPED));<br style="line-height: normal; ">    lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">    lpPerIOData->Buffer.buf = lpPerIOData->szMessage;   </p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    WSARecv(lpPerIOData->sClient,<br style="line-height: normal; ">      &lpPerIOData->Buffer,<br style="line-height: normal; ">      1,<br style="line-height: normal; ">      &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">      &lpPerIOData->Flags,<br style="line-height: normal; ">      &lpPerIOData->overlap,<br style="line-height: normal; ">      CompletionROUTINE);<br style="line-height: normal; ">}<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">鐢ㄥ畬鎴愪緥紼嬫潵瀹炵幇閲嶅彔I(yíng)/O姣旂敤浜嬩歡閫氱煡綆鍗曞緱澶氥傚湪榪欎釜妯″瀷涓紝涓葷嚎紼嬪彧鐢ㄤ笉鍋滅殑鎺ュ彈榪炴帴鍗沖彲錛涜緟鍔╃嚎紼嬪垽鏂湁娌℃湁鏂扮殑瀹㈡埛绔繛鎺ヨ寤虹珛錛屽鏋滄湁錛屽氨涓洪偅涓鎴風(fēng)濂楁帴瀛楁縺媧諱竴涓紓姝ョ殑WSARecv鎿嶄綔錛岀劧鍚庤皟鐢⊿leepEx浣跨嚎紼嬪浜庝竴縐嶅彲璀﹀憡鐨勭瓑寰呯姸鎬侊紝浠ヤ嬌寰桰/O瀹屾垚鍚嶤ompletionROUTINE鍙互琚唴鏍歌皟鐢ㄣ傚鏋滆緟鍔╃嚎紼嬩笉璋冪敤SleepEx錛屽垯鍐呮牳鍦ㄥ畬鎴愪竴嬈/O鎿嶄綔鍚庯紝鏃犳硶璋冪敤瀹屾垚渚嬬▼錛堝洜涓哄畬鎴愪緥紼嬬殑榪愯搴旇鍜屽綋鍒濇縺媧籛SARecv寮傛鎿嶄綔鐨勪唬鐮佸湪鍚屼竴涓嚎紼嬩箣鍐咃級(jí)銆?br style="line-height: normal; ">瀹屾垚渚嬬▼鍐呯殑瀹炵幇浠g爜姣旇緝綆鍗曪紝瀹冨彇鍑烘帴鏀跺埌鐨勬暟鎹紝鐒跺悗灝嗘暟鎹師灝佷笉鍔ㄧ殑鍙戦佺粰瀹㈡埛绔紝鏈鍚庨噸鏂版縺媧誨彟涓涓猈SARecv寮傛鎿嶄綔銆傛敞鎰忥紝鍦ㄨ繖閲岀敤鍒頒簡(jiǎn)“灝鵑殢鏁版嵁”銆傛垜浠湪璋冪敤WSARecv鐨勬椂鍊欙紝鍙傛暟l(fā)pOverlapped瀹為檯涓婃寚鍚戜竴涓瘮瀹冨ぇ寰楀鐨勭粨鏋凱ER_IO_OPERATION_DATA錛岃繖涓粨鏋勯櫎浜?jiǎn)WSAOVERLAPPED浠ュ錛岃繕琚垜浠檮鍔犱簡(jiǎn)緙撳啿鍖虹殑緇撴瀯淇℃伅錛屽彟澶栬繕鍖呮嫭瀹㈡埛绔鎺ュ瓧絳夐噸瑕佺殑淇℃伅銆傝繖鏍鳳紝鍦ㄥ畬鎴愪緥紼嬩腑閫氳繃鍙傛暟l(fā)pOverlapped鎷垮埌鐨勪笉浠呬粎鏄疻SAOVERLAPPED緇撴瀯錛岃繕鏈夊悗杈瑰熬闅忕殑鍖呭惈瀹㈡埛绔鎺ュ瓧鍜屾帴鏀舵暟鎹紦鍐插尯絳夐噸瑕佷俊鎭傝繖鏍風(fēng)殑C璇█鎶宸у湪鎴戝悗闈粙緇嶅畬鎴愮鍙g殑鏃跺欒繕浼?xì)鋴社敤鍒般?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">浜?瀹屾垚绔彛妯″瀷<br style="line-height: normal; ">“瀹屾垚绔彛”妯″瀷鏄縿浠婁負(fù)姝㈡渶涓哄鏉傜殑涓縐岻/O妯″瀷銆傜劧鑰岋紝鍋囪嫢涓涓簲鐢ㄧ▼搴忓悓鏃墮渶瑕佺鐞嗕負(fù)鏁頒紬澶氱殑濂楁帴瀛楋紝閭d箞閲囩敤榪欑妯″瀷錛屽線寰鍙互杈懼埌鏈浣崇殑緋葷粺鎬ц兘錛佷絾涓嶅垢鐨勬槸錛岃妯″瀷鍙傜敤浜嶹indows NT鍜學(xué)indows 2000鎿嶄綔緋葷粺銆傚洜鍏惰璁$殑澶嶆潅鎬э紝鍙湁鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忛渶瑕佸悓鏃剁鐞嗘暟鐧句箖鑷充笂鍗冧釜濂楁帴瀛楃殑鏃跺欙紝鑰屼笖甯屾湜闅忕潃緋葷粺鍐呭畨瑁呯殑CPU鏁伴噺鐨勫澶氾紝搴旂敤紼嬪簭鐨勬ц兘涔熷彲浠ョ嚎鎬ф彁鍗囷紝鎵嶅簲鑰冭檻閲囩敤“瀹屾垚绔彛”妯″瀷銆傝璁頒綇鐨勪竴涓熀鏈噯鍒欐槸錛屽亣濡傝涓篧indows NT鎴朩indows 2000寮鍙戦珮鎬ц兘鐨勬湇鍔″櫒搴旂敤錛屽悓鏃跺笇鏈涗負(fù)澶ч噺濂楁帴瀛桰/O璇鋒眰鎻愪緵鏈嶅姟錛圵eb鏈嶅姟鍣ㄤ究鏄繖鏂歸潰鐨勫吀鍨嬩緥瀛愶級(jí)錛岄偅涔圛/O瀹屾垚绔彛妯″瀷渚挎槸鏈浣抽夋嫨錛侊紙鑺傞夎嚜銆奧indows緗戠粶緙栫▼銆嬬鍏珷錛?br style="line-height: normal; ">瀹屾垚绔彛妯″瀷鏄垜鏈鍠滅埍鐨勪竴縐嶆ā鍨嬨傝櫧鐒跺叾瀹炵幇姣旇緝澶嶆潅錛堝叾瀹炴垜瑙夊緱瀹冪殑瀹炵幇姣旂敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營(yíng)/O綆鍗曞浜?jiǎn)锛?jí)錛屼絾鍏舵晥鐜囨槸鎯婁漢鐨勩傛垜鍦═鍏徃鐨勬椂鍊欐浘緇忓府鍚屼簨鍐欒繃涓涓偖浠舵湇鍔″櫒鐨勬ц兘嫻嬭瘯紼嬪簭錛岀敤鐨勫氨鏄畬鎴愮鍙fā鍨嬨傜粨鏋滆〃鏄庯紝瀹屾垚绔彛妯″瀷鍦ㄥ榪炴帴錛堟垚鍗冧笂涓囷級(jí)鐨勬儏鍐典笅錛屼粎浠呬緷闈犱竴涓や釜杈呭姪綰跨▼錛屽氨鍙互杈懼埌闈炲父楂樼殑鍚炲悙閲忋備笅闈㈡垜榪樻槸浠庝唬鐮佽璧鳳細(xì)<br style="line-height: normal; ">#include <WINSOCK2.H><br style="line-height: normal; ">#include <stdio.h></p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#define PORT    5150<br style="line-height: normal; ">#define MSGSIZE 1024</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#pragma comment(lib, "ws2_32.lib")</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef enum<br style="line-height: normal; ">{<br style="line-height: normal; ">RECV_POSTED<br style="line-height: normal; ">}OPERATION_TYPE;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef struct<br style="line-height: normal; ">{<br style="line-height: normal; ">WSAOVERLAPPED overlap;<br style="line-height: normal; ">WSABUF         Buffer;<br style="line-height: normal; ">char           szMessage[MSGSIZE];<br style="line-height: normal; ">DWORD          NumberOfBytesRecvd;<br style="line-height: normal; ">DWORD          Flags;<br style="line-height: normal; ">OPERATION_TYPE OperationType;<br style="line-height: normal; ">}PER_IO_OPERATION_DATA, *LPPER_IO_OPERATION_DATA;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">int main()<br style="line-height: normal; ">{<br style="line-height: normal; ">WSADATA                 wsaData;<br style="line-height: normal; ">SOCKET                  sListen, sClient;<br style="line-height: normal; ">SOCKADDR_IN             local, client;<br style="line-height: normal; ">DWORD                   i, dwThreadId;<br style="line-height: normal; ">int                     iaddrSize = sizeof(SOCKADDR_IN);<br style="line-height: normal; ">HANDLE                  CompletionPort = INVALID_HANDLE_VALUE;<br style="line-height: normal; ">SYSTEM_INFO             systeminfo;<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Initialize Windows Socket library<br style="line-height: normal; ">WSAStartup(0x0202, &wsaData);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create completion port<br style="line-height: normal; ">CompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create worker thread<br style="line-height: normal; ">GetSystemInfo(&systeminfo);<br style="line-height: normal; ">for (i = 0; i < systeminfo.dwNumberOfProcessors; i++)<br style="line-height: normal; ">{<br style="line-height: normal; ">    CreateThread(NULL, 0, WorkerThread, CompletionPort, 0, &dwThreadId);<br style="line-height: normal; ">}<br style="line-height: normal; "><br style="line-height: normal; ">// Create listening socket<br style="line-height: normal; ">sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Bind<br style="line-height: normal; ">local.sin_addr.S_un.S_addr = htonl(INADDR_ANY);<br style="line-height: normal; ">local.sin_family = AF_INET;<br style="line-height: normal; ">local.sin_port = htons(PORT);<br style="line-height: normal; ">bind(sListen, (struct sockaddr *)&local, sizeof(SOCKADDR_IN));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Listen<br style="line-height: normal; ">listen(sListen, 3);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Accept a connection<br style="line-height: normal; ">    sClient = accept(sListen, (struct sockaddr *)&client, &iaddrSize);<br style="line-height: normal; ">    printf("Accepted client:%s:%d\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    // Associate the newly arrived client socket with completion port<br style="line-height: normal; ">    CreateIoCompletionPort((HANDLE)sClient, CompletionPort, (DWORD)sClient, 0);<br style="line-height: normal; ">    <br style="line-height: normal; ">    // Launch an asynchronous operation for new arrived connection<br style="line-height: normal; ">    lpPerIOData = (LPPER_IO_OPERATION_DATA)HeapAlloc(<br style="line-height: normal; ">      GetProcessHeap(),<br style="line-height: normal; ">      HEAP_ZERO_MEMORY,<br style="line-height: normal; ">      sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">    lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">    lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">    lpPerIOData->OperationType = RECV_POSTED;<br style="line-height: normal; ">    WSARecv(sClient,<br style="line-height: normal; ">      &lpPerIOData->Buffer,<br style="line-height: normal; ">      1,<br style="line-height: normal; ">      &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">      &lpPerIOData->Flags,<br style="line-height: normal; ">      &lpPerIOData->overlap,<br style="line-height: normal; ">      NULL);<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">PostQueuedCompletionStatus(CompletionPort, 0xFFFFFFFF, 0, NULL);<br style="line-height: normal; ">CloseHandle(CompletionPort);<br style="line-height: normal; ">closesocket(sListen);<br style="line-height: normal; ">WSACleanup();<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID CompletionPortID)<br style="line-height: normal; ">{<br style="line-height: normal; ">HANDLE                  CompletionPort=(HANDLE)CompletionPortID;<br style="line-height: normal; ">DWORD                   dwBytesTransferred;<br style="line-height: normal; ">SOCKET                  sClient;<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    GetQueuedCompletionStatus(<br style="line-height: normal; ">      CompletionPort,<br style="line-height: normal; ">      &dwBytesTransferred,<br style="line-height: normal; ">      &sClient,<br style="line-height: normal; ">      (LPOVERLAPPED *)&lpPerIOData,<br style="line-height: normal; ">      INFINITE);<br style="line-height: normal; ">    if (dwBytesTransferred == 0xFFFFFFFF)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      return 0;<br style="line-height: normal; ">    }<br style="line-height: normal; ">    <br style="line-height: normal; ">    if (lpPerIOData->OperationType == RECV_POSTED)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      if (dwBytesTransferred == 0)<br style="line-height: normal; ">      {<br style="line-height: normal; ">        // Connection was closed by client<br style="line-height: normal; ">        closesocket(sClient);<br style="line-height: normal; ">        HeapFree(GetProcessHeap(), 0, lpPerIOData);        <br style="line-height: normal; ">      }<br style="line-height: normal; ">      else<br style="line-height: normal; ">      {<br style="line-height: normal; ">        lpPerIOData->szMessage[dwBytesTransferred] = '\0';<br style="line-height: normal; ">        send(sClient, lpPerIOData->szMessage, dwBytesTransferred, 0);<br style="line-height: normal; ">        <br style="line-height: normal; ">        // Launch another asynchronous operation for sClient<br style="line-height: normal; ">        memset(lpPerIOData, 0, sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">        lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">        lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">        lpPerIOData->OperationType = RECV_POSTED;<br style="line-height: normal; ">        WSARecv(sClient,<br style="line-height: normal; ">          &lpPerIOData->Buffer,<br style="line-height: normal; ">          1,<br style="line-height: normal; ">          &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">          &lpPerIOData->Flags,<br style="line-height: normal; ">          &lpPerIOData->overlap,<br style="line-height: normal; ">          NULL);<br style="line-height: normal; ">      }<br style="line-height: normal; ">    }<br style="line-height: normal; ">}<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br style="line-height: normal; ">棣栧厛錛岃璇翠富綰跨▼錛?br style="line-height: normal; ">1.鍒涘緩瀹屾垚绔彛瀵硅薄<br style="line-height: normal; ">2.鍒涘緩宸ヤ綔鑰呯嚎紼嬶紙榪欓噷宸ヤ綔鑰呯嚎紼嬬殑鏁伴噺鏄寜鐓PU鐨勪釜鏁版潵鍐沖畾鐨勶紝榪欐牱鍙互杈懼埌鏈浣蟲ц兘錛?br style="line-height: normal; ">3.鍒涘緩鐩戝惉濂楁帴瀛楋紝緇戝畾錛岀洃鍚紝鐒跺悗紼嬪簭榪涘叆寰幆<br style="line-height: normal; ">4.鍦ㄥ驚鐜腑錛屾垜鍋氫簡(jiǎn)浠ヤ笅鍑犱歡浜嬫儏錛?br style="line-height: normal; ">(1).鎺ュ彈涓涓鎴風(fēng)榪炴帴<br style="line-height: normal; ">(2).灝嗚瀹㈡埛绔鎺ュ瓧涓庡畬鎴愮鍙g粦瀹氬埌涓璧?榪樻槸璋冪敤CreateIoCompletionPort錛屼絾榪欐鐨勪綔鐢ㄤ笉鍚?錛屾敞鎰忥紝鎸夐亾鐞嗘潵璁詫紝姝ゆ椂浼犻掔粰C(jī)reateIoCompletionPort鐨勭涓変釜鍙傛暟搴旇鏄竴涓畬鎴愰敭錛屼竴鑸潵璁詫紝紼嬪簭閮芥槸浼犻掍竴涓崟鍙ユ焺鏁版嵁緇撴瀯鐨勫湴鍧錛岃鍗曞彞鏌勬暟鎹寘鍚簡(jiǎn)鍜岃瀹㈡埛绔繛鎺ユ湁鍏崇殑淇℃伅錛岀敱浜庢垜浠彧鍏沖績(jī)濂楁帴瀛楀彞鏌勶紝鎵浠ョ洿鎺ュ皢濂楁帴瀛楀彞鏌勪綔涓哄畬鎴愰敭浼犻掞紱<br style="line-height: normal; ">(3).瑙﹀彂涓涓猈SARecv寮傛璋冪敤錛岃繖嬈″張鐢ㄥ埌浜?#8220;灝鵑殢鏁版嵁”錛屼嬌鎺ユ敹鏁版嵁鎵鐢ㄧ殑緙撳啿鍖虹揣璺熷湪WSAOVERLAPPED瀵硅薄涔嬪悗錛屾澶栵紝榪樻湁鎿嶄綔綾誨瀷絳夐噸瑕佷俊鎭?br style="line-height: normal; "><br style="line-height: normal; ">鍦ㄥ伐浣滆呯嚎紼嬬殑寰幆涓紝鎴戜滑<br style="line-height: normal; ">1.璋冪敤GetQueuedCompletionStatus鍙栧緱鏈I/O鐨勭浉鍏充俊鎭紙渚嬪濂楁帴瀛楀彞鏌勩佷紶閫佺殑瀛楄妭鏁般佸崟I/O鏁版嵁緇撴瀯鐨勫湴鍧絳夌瓑錛?br style="line-height: normal; ">2.閫氳繃鍗旾/O鏁版嵁緇撴瀯鎵懼埌鎺ユ敹鏁版嵁緙撳啿鍖猴紝鐒跺悗灝嗘暟鎹師灝佷笉鍔ㄧ殑鍙戦佸埌瀹㈡埛绔?br style="line-height: normal; ">3.鍐嶆瑙﹀彂涓涓猈SARecv寮傛鎿嶄綔</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">鍏?浜旂I/O妯″瀷鐨勬瘮杈?br style="line-height: normal; ">鎴戜細(xì)浠庝互涓嬪嚑涓柟闈㈡潵榪涜姣旇緝<br style="line-height: normal; ">*鏈夋棤姣忕嚎紼?4榪炴帴鏁伴檺鍒?br style="line-height: normal; ">濡傛灉鍦ㄩ夋嫨妯″瀷涓病鏈夐噸鏂板畾涔塅D_SETSIZE瀹忥紝鍒欐瘡涓猣d_set榛樿鍙互瑁呬笅64涓猄OCKET銆傚悓鏍風(fēng)殑錛屽彈MAXIMUM_WAIT_OBJECTS瀹忕殑褰卞搷錛屼簨浠墮夋嫨銆佺敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營(yíng)/O閮芥湁姣忕嚎紼嬫渶澶?4榪炴帴鏁伴檺鍒躲傚鏋滆繛鎺ユ暟鎴愬崈涓婁竾錛屽垯蹇呴』瀵瑰鎴風(fēng)濂楁帴瀛楄繘琛屽垎緇勶紝榪欐牱錛屽娍蹇呭鍔犵▼搴忕殑澶嶆潅搴︺?br style="line-height: normal; ">鐩稿弽錛屽紓姝ラ夋嫨銆佺敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營(yíng)/O鍜屽畬鎴愮鍙d笉鍙楁闄愬埗銆?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*綰跨▼鏁?br style="line-height: normal; ">闄や簡(jiǎn)寮傛閫夋嫨浠ュ錛屽叾浠栨ā鍨嬭嚦灝戦渶瑕?涓嚎紼嬨備竴涓富綰跨▼鍜屼竴涓緟鍔╃嚎紼嬨傚悓鏍風(fēng)殑錛屽鏋滆繛鎺ユ暟澶т簬64錛屽垯閫夋嫨妯″瀷銆佷簨浠墮夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營(yíng)/O鐨勭嚎紼嬫暟榪樿澧炲姞銆?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*瀹炵幇鐨勫鏉傚害<br style="line-height: normal; ">鎴戠殑涓漢鐪嬫硶鏄紝鍦ㄥ疄鐜伴毦搴︿笂錛屽紓姝ラ夋嫨<閫夋嫨<鐢ㄥ畬鎴愪緥紼嬪疄鐜扮殑閲嶅彔I(yíng)/O<浜嬩歡閫夋嫨<瀹屾垚绔彛<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營(yíng)/O</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*鎬ц兘<br style="line-height: normal; ">鐢變簬閫夋嫨妯″瀷涓瘡嬈¢兘瑕侀噸璁捐闆嗭紝鍦╯elect鍑芥暟榪斿洖鍚庤繕瑕侀拡瀵規(guī)墍鏈夊鎺ュ瓧榪涜閫愪竴嫻嬭瘯錛屾垜鐨勬劅瑙夋槸鏁堢巼姣旇緝宸紱瀹屾垚绔彛鍜岀敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營(yíng)/O鍩烘湰涓婁笉娑夊強(qiáng)鍏ㄥ眬鏁版嵁錛屾晥鐜囧簲璇ユ槸鏈楂樼殑錛岃屼笖鍦ㄥ澶勭悊鍣ㄦ儏褰笅瀹屾垚绔彛榪樿楂樹竴浜涳紱浜嬩歡閫夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營(yíng)/O鍦ㄥ疄鐜版満鍒朵笂閮芥槸閲囩敤WSAWaitForMultipleEvents錛屾劅瑙夋晥鐜囧樊涓嶅錛涜嚦浜庡紓姝ラ夋嫨錛屼笉濂芥瘮杈冦傛墍浠ユ垜鐨勭粨璁烘槸:閫夋嫨<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營(yíng)/O<浜嬩歡閫夋嫨<鐢ㄥ畬鎴愪緥紼嬪疄鐜扮殑閲嶅彔I(yíng)/O<瀹屾垚绔彛</p> <img src ="http://www.shnenglu.com/kenwell/aggbug/122086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範(fàn)</a> 2010-08-03 17:27 <a href="http://www.shnenglu.com/kenwell/archive/2010/08/03/122086.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title> 寰堝菇榛樼殑璁茶В鍏Socket I/O妯″瀷(杞澆錛?/title><link>http://www.shnenglu.com/kenwell/archive/2010/08/03/122069.html</link><dc:creator>c++ 瀛︿範(fàn)</dc:creator><author>c++ 瀛︿範(fàn)</author><pubDate>Tue, 03 Aug 2010 07:50:00 GMT</pubDate><guid>http://www.shnenglu.com/kenwell/archive/2010/08/03/122069.html</guid><wfw:comment>http://www.shnenglu.com/kenwell/comments/122069.html</wfw:comment><comments>http://www.shnenglu.com/kenwell/archive/2010/08/03/122069.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/kenwell/comments/commentRss/122069.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/kenwell/services/trackbacks/122069.html</trackback:ping><description><![CDATA[     鎽樿: 鏈枃綆鍗曚粙緇嶄簡(jiǎn)褰撳墠Windows鏀寔鐨勫悇縐峉ocket I/O妯″瀷錛屽鏋滀綘鍙戠幇鍏朵腑瀛樺湪浠涔堥敊璇鍔″繀璧愭暀銆備竴錛歴elect妯″瀷浜岋細(xì)WSAAsyncSelect妯″瀷涓夛細(xì)WSAEventSelect妯″瀷鍥涳細(xì)Overlapped I/O 浜嬩歡閫氱煡妯″瀷浜旓細(xì)Overlapped I/O 瀹屾垚渚嬬▼妯″瀷鍏細(xì)IOCP妯″瀷鑰侀檲鏈変竴涓湪澶栧湴宸ヤ綔鐨勫コ鍎匡紝涓嶈兘緇忓父鍥炴潵錛岃侀檲鍜屽ス閫氳繃淇′歡鑱旂郴銆備粬浠殑淇′細(xì)琚偖閫掑憳鎶曢掑埌浠栦滑鐨?..  <a href='http://www.shnenglu.com/kenwell/archive/2010/08/03/122069.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/kenwell/aggbug/122069.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範(fàn)</a> 2010-08-03 15:50 <a href="http://www.shnenglu.com/kenwell/archive/2010/08/03/122069.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Printing ONE TWO THREE http://www.shnenglu.com/kenwell/archive/2008/10/11/63760.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Sat, 11 Oct 2008 11:51:00 GMThttp://www.shnenglu.com/kenwell/archive/2008/10/11/63760.htmlhttp://www.shnenglu.com/kenwell/comments/63760.htmlhttp://www.shnenglu.com/kenwell/archive/2008/10/11/63760.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/63760.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/63760.html- You're given the following program:
--------------------------------
int main()
{
     printf("TWO\n");
     return 0;
}
---------------------------------
 
Add any code above or below the lines so that the output is
 
ONE
TWO
THREE
Give 10 different ways to do this and which of them are specific to C++?

: just comment it out (already mentioned)
#include <iostream>
int main() { std::cout << "ONE\nTWO\nTHREE\n"; return 0; }
/*
...
*/
 
2: use #if or #ifdef
#include <iostream>
#ifdef foo
...
#else
int main() { std::cout << "ONE\nTWO\nTHREE\n"; return 0; }
#endif
 
3: redefine printf (already mentioned)
#include <iostream>
#define printf(foo) std::cout << "ONE\n" << foo << "THREE\n";
...
 
4: overload printf (already mentioned, c++ specific)
void printf(const char * s);
...
#include <iostream>
void printf(const char * s) { std::cout << "ONE\n" << s << "THREE\n"; }
 
5: template printf (c++ specific)
void foo(const char * s);
template<typename T> void printf(T s) { foo(s); }
...
#include <iostream>
void foo(const char * s) { std::cout << "ONE\n" << s << "THRE\n"; }
 
6: redefine main
#include <iostream>
int foo();
int main() {std::cout << "ONE\n"; foo(); std::cout << "THREE\n"; return 0; }
#define main foo
...
 
7: put main in a namespace (c++ specific)
#include <iostream>
namespace foo {
...
};
int main() { std::cout << "ONE\n"; foo::main(); std::cout << "THREE\n"; return 0; }
 
8: put main in a class or struct (c++ specific)
#include <iostream>
struct foo {
...
};
int main() { foo bar; std::cout << "ONE\n"; bar.main(); std::cout << "THREE\n"; return 0; }
 
9: use #define to remove keywords
#include <iostream>
int main() {
  printf("ONE\n");
#define main() do
#define return
#define int
...
 while (!printf("THREE\n"));
#undef return
  return 0;
}
 
10: abuse a class or struct constructor (c++ specific)
struct printf { printf(const char * s); };
...
#include <iostream>
printf::printf(const char * s) { std::cout << "ONE\n" << s << "THREE\n"; }
 


]]>
ubuntu鍛戒護(hù)琛屼慨鏀圭綉緇滈厤緗柟娉?/title><link>http://www.shnenglu.com/kenwell/archive/2008/07/22/56832.html</link><dc:creator>c++ 瀛︿範(fàn)</dc:creator><author>c++ 瀛︿範(fàn)</author><pubDate>Tue, 22 Jul 2008 02:41:00 GMT</pubDate><guid>http://www.shnenglu.com/kenwell/archive/2008/07/22/56832.html</guid><wfw:comment>http://www.shnenglu.com/kenwell/comments/56832.html</wfw:comment><comments>http://www.shnenglu.com/kenwell/archive/2008/07/22/56832.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/kenwell/comments/commentRss/56832.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/kenwell/services/trackbacks/56832.html</trackback:ping><description><![CDATA[<div id="qscbzan" class="postentry"> <p>/etc/network/interfaces<br>鎵撳紑鍚庨噷闈㈠彲璁劇疆DHCP鎴栨墜鍔ㄨ緗潤(rùn)鎬乮p銆傚墠闈uto eth0錛岃緗戝崱寮鏈鴻嚜鍔ㄦ寕杞?</p> <p><strong>1. </strong><strong>浠HCP鏂瑰紡</strong><strong>閰嶇疆</strong><strong>緗戝崱</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:<br><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>騫剁敤涓嬮潰鐨勮鏉ユ浛鎹㈡湁鍏砮th0鐨勮:<br><code><font face="鏂板畫浣?># The primary network interface - use DHCP to find our address<br>auto eth0<br>iface eth0 inet dhcp</font></code></p> <p>鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><font face="鏂板畫浣?><code>sudo /etc/init.d/networking restart</code><br></font>涔熷彲浠ュ湪鍛戒護(hù)琛屼笅鐩存帴杈撳叆涓嬮潰鐨勫懡浠ゆ潵鑾峰彇鍦板潃</p> <p><font face="鏂板畫浣?><code>sudo dhclient eth0</code><br></font><strong><br>2. 涓虹綉鍗¢厤緗潤(rùn)鎬両P鍦板潃</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:</p> <p><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>騫剁敤涓嬮潰鐨勮鏉ユ浛鎹㈡湁鍏砮th0鐨勮:# The primary network interface<br><code><font face="鏂板畫浣?>auto eth0<br>iface eth0 inet static<br>address 192.168.3.90<br>gateway 192.168.3.1<br>netmask 255.255.255.0<br>#network 192.168.3.0<br>#broadcast 192.168.3.255</font></code></p> <p>灝嗕笂闈㈢殑ip鍦板潃絳変俊鎭崲鎴愪綘鑷繁灝卞彲浠ヤ簡(jiǎn).鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><code><font face="鏂板畫浣?>sudo /etc/init.d/networking restart</font></code></p> <p><strong>3. 璁懼畾絎簩涓狪P鍦板潃(铏氭嫙IP鍦板潃)</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:</p> <p><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>鍦ㄨ鏂囦歡涓坊鍔犲涓嬬殑琛?<br><code><font face="鏂板畫浣?>auto eth0:1<br>iface eth0:1 inet static<br>address 192.168.1.60<br>netmask 255.255.255.0<br>network x.x.x.x<br>broadcast x.x.x.x<br>gateway x.x.x.x</font></code></p> <p>鏍規(guī)嵁浣犵殑鎯呭喌濉笂鎵鏈夎濡俛ddress,netmask,network,broadcast鍜実ateways絳変俊鎭?<br>鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><code><font face="鏂板畫浣?>sudo /etc/init.d/networking restart</font></code></p> <p><strong>4. 璁劇疆涓繪満鍚嶇О(hostname)</strong></p> <p>浣跨敤涓嬮潰鐨勫懡浠ゆ潵鏌ョ湅褰撳墠涓繪満鐨勪富鏈哄悕縐?</p> <p><code><font face="鏂板畫浣?>sudo /bin/hostname</font></code></p> <p>浣跨敤涓嬮潰鐨勫懡浠ゆ潵璁劇疆褰撳墠涓繪満鐨勪富鏈哄悕縐?<br><code><br><font face="鏂板畫浣?>sudo /bin/hostname newname</font></code></p> <p>緋葷粺鍚姩鏃?瀹冧細(xì)浠?etc/hostname鏉ヨ鍙栦富鏈虹殑鍚嶇О.</p> <p>鍏充簬璁劇疆涓繪満鍚嶇О鐨勬洿澶氫俊鎭?璇瘋闂?a target="_blank"><font color="#0000ff">榪欓噷</font></a></p> <p><strong>5. 閰嶇疆DNS</strong></p> <p>棣栧厛,浣犲彲浠ュ湪/etc/hosts涓姞鍏ヤ竴浜涗富鏈哄悕縐板拰榪欎簺涓繪満鍚嶇О瀵瑰簲鐨処P鍦板潃,榪欐槸綆鍗曚嬌鐢ㄦ湰鏈虹殑闈?rùn)鎬佹煡璇?</p> <p>瑕佽闂瓺NS 鏈嶅姟鍣ㄦ潵榪涜鏌ヨ,闇瑕佽緗?etc/resolv.conf鏂囦歡.<br>鍋囪DNS鏈嶅姟鍣ㄧ殑IP鍦板潃鏄?92.168.3.2, 閭d箞/etc/resolv.conf鏂囦歡鐨勫唴瀹瑰簲涓?</p> <p><code><font face="鏂板畫浣?>search test.com<br>nameserver 192.168.3.2</font></code></p> </div> <p class="postmeta">2008騫?2鏈?5鏃?鏄熸湡浜?浜?10:07 am · 鍙戣〃鍦? <a title="鏄劇ずUnix/Linux鐨勬墍鏈夋枃绔? rel="category tag"><font color="#0000ff">Unix/Linux</font></a> </p> <div id="uqgenof" class="postentry"> <p>/etc/network/interfaces<br>鎵撳紑鍚庨噷闈㈠彲璁劇疆DHCP鎴栨墜鍔ㄨ緗潤(rùn)鎬乮p銆傚墠闈uto eth0錛岃緗戝崱寮鏈鴻嚜鍔ㄦ寕杞?</p> <p><strong>1. </strong><strong>浠HCP鏂瑰紡</strong><strong>閰嶇疆</strong><strong>緗戝崱</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:<br><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>騫剁敤涓嬮潰鐨勮鏉ユ浛鎹㈡湁鍏砮th0鐨勮:<br><code><font face="鏂板畫浣?># The primary network interface - use DHCP to find our address<br>auto eth0<br>iface eth0 inet dhcp</font></code></p> <p>鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><font face="鏂板畫浣?><code>sudo /etc/init.d/networking restart</code><br></font>涔熷彲浠ュ湪鍛戒護(hù)琛屼笅鐩存帴杈撳叆涓嬮潰鐨勫懡浠ゆ潵鑾峰彇鍦板潃</p> <p><font face="鏂板畫浣?><code>sudo dhclient eth0</code><br></font><strong><br>2. 涓虹綉鍗¢厤緗潤(rùn)鎬両P鍦板潃</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:</p> <p><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>騫剁敤涓嬮潰鐨勮鏉ユ浛鎹㈡湁鍏砮th0鐨勮:# The primary network interface<br><code><font face="鏂板畫浣?>auto eth0<br>iface eth0 inet static<br>address 192.168.3.90<br>gateway 192.168.3.1<br>netmask 255.255.255.0<br>#network 192.168.3.0<br>#broadcast 192.168.3.255</font></code></p> <p>灝嗕笂闈㈢殑ip鍦板潃絳変俊鎭崲鎴愪綘鑷繁灝卞彲浠ヤ簡(jiǎn).鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><code><font face="鏂板畫浣?>sudo /etc/init.d/networking restart</font></code></p> <p><strong>3. 璁懼畾絎簩涓狪P鍦板潃(铏氭嫙IP鍦板潃)</strong></p> <p>緙栬緫鏂囦歡/etc/network/interfaces:</p> <p><code><font face="鏂板畫浣?>sudo vi /etc/network/interfaces</font></code></p> <p>鍦ㄨ鏂囦歡涓坊鍔犲涓嬬殑琛?<br><code><font face="鏂板畫浣?>auto eth0:1<br>iface eth0:1 inet static<br>address 192.168.1.60<br>netmask 255.255.255.0<br>network x.x.x.x<br>broadcast x.x.x.x<br>gateway x.x.x.x</font></code></p> <p>鏍規(guī)嵁浣犵殑鎯呭喌濉笂鎵鏈夎濡俛ddress,netmask,network,broadcast鍜実ateways絳変俊鎭?<br>鐢ㄤ笅闈㈢殑鍛戒護(hù)浣跨綉緇滆緗敓鏁?<br><code><font face="鏂板畫浣?>sudo /etc/init.d/networking restart</font></code></p> <p><strong>4. 璁劇疆涓繪満鍚嶇О(hostname)</strong></p> <p>浣跨敤涓嬮潰鐨勫懡浠ゆ潵鏌ョ湅褰撳墠涓繪満鐨勪富鏈哄悕縐?</p> <p><code><font face="鏂板畫浣?>sudo /bin/hostname</font></code></p> <p>浣跨敤涓嬮潰鐨勫懡浠ゆ潵璁劇疆褰撳墠涓繪満鐨勪富鏈哄悕縐?<br><code><br><font face="鏂板畫浣?>sudo /bin/hostname newname</font></code></p> <p>緋葷粺鍚姩鏃?瀹冧細(xì)浠?etc/hostname鏉ヨ鍙栦富鏈虹殑鍚嶇О.</p> <p>鍏充簬璁劇疆涓繪満鍚嶇О鐨勬洿澶氫俊鎭?璇瘋闂?a target="_blank"><font color="#0000ff">榪欓噷</font></a></p> <p><strong>5. 閰嶇疆DNS</strong></p> <p>棣栧厛,浣犲彲浠ュ湪/etc/hosts涓姞鍏ヤ竴浜涗富鏈哄悕縐板拰榪欎簺涓繪満鍚嶇О瀵瑰簲鐨処P鍦板潃,榪欐槸綆鍗曚嬌鐢ㄦ湰鏈虹殑闈?rùn)鎬佹煡璇?</p> <p>瑕佽闂瓺NS 鏈嶅姟鍣ㄦ潵榪涜鏌ヨ,闇瑕佽緗?etc/resolv.conf鏂囦歡.<br>鍋囪DNS鏈嶅姟鍣ㄧ殑IP鍦板潃鏄?92.168.3.2, 閭d箞/etc/resolv.conf鏂囦歡鐨勫唴瀹瑰簲涓?</p> <p><code><font face="鏂板畫浣?>search test.com<br>nameserver 192.168.3.2</font></code></p> </div><img src ="http://www.shnenglu.com/kenwell/aggbug/56832.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範(fàn)</a> 2008-07-22 10:41 <a href="http://www.shnenglu.com/kenwell/archive/2008/07/22/56832.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>c++ 涓敤IXMLHTTPRequest鍚戞湇鍔″櫒post Xml鏁版嵁http://www.shnenglu.com/kenwell/archive/2008/05/21/50663.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Wed, 21 May 2008 10:41:00 GMThttp://www.shnenglu.com/kenwell/archive/2008/05/21/50663.htmlhttp://www.shnenglu.com/kenwell/comments/50663.htmlhttp://www.shnenglu.com/kenwell/archive/2008/05/21/50663.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/50663.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/50663.html#include <string>
#include 
<iostream>
#import 
<msxml4.dll>

void SendData(std::wstring url, std::wstring username, std::wstring password)
{

    HRESULT hr;
    MSXML2::IXMLHTTPRequestPtr pIXMLHTTPRequest;
    MSXML2::IXMLDOMDocumentPtr pXMLDoc;
    std::wstring wvarQuery(L
"username=");
    wvarQuery.append(username);
    wvarQuery.append(L
"&password=");
    wvarQuery.append(password);
    _variant_t vartQueryFields(wvarQuery.c_str());

    
try
    {
        CoInitialize(NULL);
        hr
=pIXMLHTTPRequest.CreateInstance(__uuidof(MSXML2::XMLHTTP));
        SUCCEEDED(hr) 
? 0 : throw hr;

        hr
=pIXMLHTTPRequest->open("POST", url.c_str(), 
            
false);
        SUCCEEDED(hr) 
? 0 : throw hr;
        
//濡傛灉瑕佸悜鏈嶅姟鍣╬ost鏁版嵁錛岃繖涓湴鏂逛竴瀹氳璁劇疆涓篴pplication/x-www-form-urlencoded
        pIXMLHTTPRequest->setRequestHeader("Content-Type""application/x-www-form-urlencoded");

        hr 
= pIXMLHTTPRequest->send( vartQueryFields );
        SUCCEEDED(hr) 
? 0 : throw hr;
        
//鎷垮埌榪斿洖鏉ョ殑xml鏁版嵁
        pXMLDoc=pIXMLHTTPRequest->responseXML;
        
//鍚庨潰灝辨槸瀵規(guī)嬁鍥炴潵鐨剎ml鏁版嵁榪涜瑙f瀽錛屼富瑕佹槸dom鏂規(guī)硶
    }
    
catch()
    {
        
if(pIXMLHTTPRequest)
            pIXMLHTTPRequest.Release();
        
if(pXMLDoc)
            pXMLDoc.Release();
        CoUninitialize();
    }
}


int main()
{
    SendData(L
"http://localhost/login.php", L"kenwell", L"kenwell");
}



]]>
c++ string 鍜寃string 涔嬮棿鐨勪簰鐩歌漿鎹㈠嚱鏁?/title><link>http://www.shnenglu.com/kenwell/archive/2008/05/21/50661.html</link><dc:creator>c++ 瀛︿範(fàn)</dc:creator><author>c++ 瀛︿範(fàn)</author><pubDate>Wed, 21 May 2008 10:23:00 GMT</pubDate><guid>http://www.shnenglu.com/kenwell/archive/2008/05/21/50661.html</guid><wfw:comment>http://www.shnenglu.com/kenwell/comments/50661.html</wfw:comment><comments>http://www.shnenglu.com/kenwell/archive/2008/05/21/50661.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.shnenglu.com/kenwell/comments/commentRss/50661.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/kenwell/services/trackbacks/50661.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">></span><span style="color: #000000;"><br>std::</span><span style="color: #0000ff;">string</span><span style="color: #000000;"> ws2s(</span><span style="color: #0000ff;">const</span><span style="color: #000000;"> std::wstring</span><span style="color: #000000;">&</span><span style="color: #000000;"> ws)<br>{<br>    std::</span><span style="color: #0000ff;">string</span><span style="color: #000000;"> curLocale </span><span style="color: #000000;">=</span><span style="color: #000000;"> setlocale(LC_ALL, NULL);        </span><span style="color: #008000;">//</span><span style="color: #008000;"> curLocale = "C";</span><span style="color: #008000;"><br></span><span style="color: #000000;">    setlocale(LC_ALL, </span><span style="color: #000000;">"</span><span style="color: #000000;">chs</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>    </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> wchar_t</span><span style="color: #000000;">*</span><span style="color: #000000;"> _Source </span><span style="color: #000000;">=</span><span style="color: #000000;"> ws.c_str();<br>    size_t _Dsize </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">2</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;"> ws.size() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>    </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">_Dest </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> </span><span style="color: #0000ff;">char</span><span style="color: #000000;">[_Dsize];<br>    memset(_Dest,</span><span style="color: #000000;">0</span><span style="color: #000000;">,_Dsize);<br>    wcstombs(_Dest,_Source,_Dsize);<br>    std::</span><span style="color: #0000ff;">string</span><span style="color: #000000;"> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> _Dest;<br>    delete []_Dest;<br>    setlocale(LC_ALL, curLocale.c_str());<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> result;<br>}<br><br>std::wstring s2ws(</span><span style="color: #0000ff;">const</span><span style="color: #000000;"> std::</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&</span><span style="color: #000000;"> s)<br>{<br>    setlocale(LC_ALL, </span><span style="color: #000000;">"</span><span style="color: #000000;">chs</span><span style="color: #000000;">"</span><span style="color: #000000;">); <br>    </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">char</span><span style="color: #000000;">*</span><span style="color: #000000;"> _Source </span><span style="color: #000000;">=</span><span style="color: #000000;"> s.c_str();<br>    size_t _Dsize </span><span style="color: #000000;">=</span><span style="color: #000000;"> s.size() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>    wchar_t </span><span style="color: #000000;">*</span><span style="color: #000000;">_Dest </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> wchar_t[_Dsize];<br>    wmemset(_Dest, </span><span style="color: #000000;">0</span><span style="color: #000000;">, _Dsize);<br>    mbstowcs(_Dest,_Source,_Dsize);<br>    std::wstring result </span><span style="color: #000000;">=</span><span style="color: #000000;"> _Dest;<br>    delete []_Dest;<br>    setlocale(LC_ALL, </span><span style="color: #000000;">"</span><span style="color: #000000;">C</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> result;<br>}<br></span></div> <br>榪欎簺閮芥槸鏈榪戣嚜宸卞湪寮鍙戦」鐩腑鐢ㄥ埌鐨?br><img src ="http://www.shnenglu.com/kenwell/aggbug/50661.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範(fàn)</a> 2008-05-21 18:23 <a href="http://www.shnenglu.com/kenwell/archive/2008/05/21/50661.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>c++緇忓吀涔︾睄鎺ㄨ崘鍜屼笅杞?/title><link>http://www.shnenglu.com/kenwell/archive/2007/10/24/35065.html</link><dc:creator>c++ 瀛︿範(fàn)</dc:creator><author>c++ 瀛︿範(fàn)</author><pubDate>Wed, 24 Oct 2007 08:45:00 GMT</pubDate><guid>http://www.shnenglu.com/kenwell/archive/2007/10/24/35065.html</guid><wfw:comment>http://www.shnenglu.com/kenwell/comments/35065.html</wfw:comment><comments>http://www.shnenglu.com/kenwell/archive/2007/10/24/35065.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.shnenglu.com/kenwell/comments/commentRss/35065.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/kenwell/services/trackbacks/35065.html</trackback:ping><description><![CDATA[緇欏涔?fàn)c++鐨勬柊鎵嬶紝榪欎簺涔︾睄閮芥槸寰堢粡鍏哥殑銆傜粡鍏鎬腑鐨勭粡鍏?br>娣卞害鎺㈢儲(chǔ)C++瀵硅薄妯″瀷<br>鑻辨枃鐗?http://www.nengxia.com/soft.asp?id=5<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=19<br><br>Modern C++ Design<br>http://www.nengxia.com/soft.asp?id=7<br><br>c++緙栫▼鎬濇兂<br>絎竴鍗鳳細(xì)<br>涓枃鐗?http://www.nengxia.com/soft.asp?id=1039<br>鑻辨枃鐗堬細(xì) Prentice Hall Bruce Eckel Thinking In C++, Second EditionVolume.1<br>絎簩鍗鳳細(xì)<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1040<br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1041<br><br><br>c++ Programming language <br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1038<br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=368 <br><br>C++ Primer<br>絎笁鐗堜腑鏂囩増錛歨ttp://www.nengxia.com/soft.asp?id=6<br>絎洓鐗?br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=117<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=635<br>c++ primer 棰樿В<br>http://www.nengxia.com/soft.asp?id=17<br><br><br>C++ Primer plus 絎?鐗堜腑鏂囷細(xì)<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=987<br>鑻辨枃鐗堬細(xì)<br>Third.Editionhttp://www.nengxia.com/soft.asp?id=1037<br>Special.Edition錛歨ttp://www.nengxia.com/soft.asp?id=369<br><br><br>Effective C++<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=9<br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1033<br><br>More Effective C++<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=8<br><br>STL婧愮爜鍓栨瀽<br>http://www.nengxia.com/soft.asp?id=11<br><br><br>c++ template<br>鑻辨枃鐗堬細(xì)<br>http://www.nengxia.com/soft.asp?id=1034<br>綆浣撲腑鏂囩増錛?br>http://www.nengxia.com/soft.asp?id=15<br>綣佷綋涓枃鐗堬細(xì)<br>http://www.nengxia.com/soft.asp?id=16<br><br>Effective STL<br>http://www.nengxia.com/soft.asp?id=54<br><br>c++ 鏍囧噯搴?br>http://www.nengxia.com/soft.asp?id=47<br><br>Exception c++<br>涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1035<br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=18<br><br>More Excetption c++<br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=20<br><br>C++ Coding Standards:<br>http://www.nengxia.com/soft.asp?id=114<br><br>STL杞繪澗鍏ラ棬<br>http://www.nengxia.com/soft.asp?id=162<br><br>c/c++鏍囧噯鍑芥暟搴?涓枃鐗?br>http://www.nengxia.com/soft.asp?id=641<br><br>the design and evolution of c++<br>鑻辨枃鐗堬細(xì)http://nengxia.com/soft.asp?id=1042<br><br>楂樿川閲廋++緙栫▼鎸囧崡<br>http://www.nengxia.com/soft.asp?id=1043<br><br><br><br><img src ="http://www.shnenglu.com/kenwell/aggbug/35065.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範(fàn)</a> 2007-10-24 16:45 <a href="http://www.shnenglu.com/kenwell/archive/2007/10/24/35065.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓婃搗浜ら氬ぇ瀛?006騫村璇曚笂鏈洪 (杞級(jí)http://www.shnenglu.com/kenwell/archive/2006/03/31/4862.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Fri, 31 Mar 2006 11:16:00 GMThttp://www.shnenglu.com/kenwell/archive/2006/03/31/4862.htmlhttp://www.shnenglu.com/kenwell/comments/4862.htmlhttp://www.shnenglu.com/kenwell/archive/2006/03/31/4862.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/4862.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/4862.html鏈鐩槸鎳掔尓涓瀛椾竴瀛楁暡涓婄數(shù)鑴戠殑錛岃漿杞借灝婇噸鎳掔尓鐨勫姵鍔ㄦ垚鏋滐紝娉ㄦ槑杞嚜鎳掔尓鐨勭獫紿?a >http://spaces.msn.com/davidblogs/錛岃祫婧愬叡浜紝璋㈣阿鍚堜綔銆?br />鎳掔尓紼嶅悗緇欏嚭鑷繁鍋氱殑鍙傝冭В絳旓紝甯屾湜鑳藉拰澶у澶氬浜ゆ祦銆?/div>
緙栫▼鐜錛歏C++6
鑰冭瘯鏃墮棿錛?灝忔椂
Problem A.Fibonacci
Input:聽聽聽聽聽聽聽聽聽 聽fib.in
Output:聽聽聽聽聽聽聽 Standard Output
Time limit:聽聽聽 聽5 second
Memory limit: 64 megabytes
Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurrence:
F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2
Write a program to calculate the Fibonacci Numbers.
Input
The input file contains a number n and you are expected to calculate Fn.(0<=n<=30)

Output
Print a number Fn on a separate line,which means the nth Fibonacci Number.
Example
fib.in聽聽聽聽聽聽 Standard Output
1聽聽聽聽聽聽聽聽聽聽聽 1
2聽聽聽聽聽聽聽聽聽聽聽 1
3聽聽聽聽聽聽聽聽聽聽聽 2
4聽聽聽聽聽聽聽聽聽聽聽 3
5聽聽聽聽聽聽聽聽聽聽聽 5
6聽聽聽聽聽聽聽聽聽聽聽 8

Problem B.WERTYU
Input:聽聽聽聽聽聽聽聽聽 聽wertyu.in
Output:聽聽聽聽聽聽 聽 Standard Output
Time limit:聽聽聽聽 聽5 second
Memory limit:聽 64 megabytes
Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
A common typing error is to place the hands on the keyboard one row to the right of the correct position.So "Q" is typed as "W" and "J" is typed as "K" and so on.You are to decode a message typed in this manner.
` 1 2 3 4 5 6 7 8 9 0 - = BackSp
Tab Q W E R T Y U I O P [ ] \
A S D F G H J K L ; ' Enter
Z聽 X聽 C聽 V聽 B聽 N聽 M聽 ,聽 .聽 /
Control Alt聽 Space聽 Alt Control
Input
The input file consist of several lines of text.Each line may contain digits,spaces,upper case letters(except Q,A,Z),or punctuation shown above(except back-quote(') which is left to the key "1").Keys labelled with words [Tab,BackSp,Control,etc.] are not represented in the input.
Output
You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above.Spaces in the input should be echoed in the output.
Example
wertyu.in聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 聽Standard Output
O S, GOMR YPFSU/聽聽聽聽聽聽聽 I AM FINE TODAY.
Problem C.String Matching
Input:聽聽聽聽聽聽聽聽聽 聽聽matching.in
Output:聽聽聽聽聽聽 聽 Standard Output
Time limit:聽聽聽聽 聽5 second
Memory limit:聽 64 megabytes
Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
Finding all occurrences of a pattern in a text is a problem that arises frequently in text-editing programs.Typically,the text is a document being edited,and the pattern searched for is a particular word supplied by the user.
We assume that the text is an array T[1..n] of length n and that the pattern is an array P[1..m] of length m<=n.We further assume that the elements of P and T are all alphabets(鈭?{a,b...,z}).The character arrays P and T are often called strings of characters.
We say that pattern P occurs with shift s in the text T if 0<=s<=n and T[s+1..s+m] = P[1..m](that is if T[s+j]=P[j],for 1<=j<=m).
If P occurs with shift s in T,then we call s a valid shift;otherwise,we call s a invalid shift.
Your task is to calculate the number of vald shifts for the given text T and pattern P.
Input
In the input file,there are two strings T and P on a line,separated by a single space.You may assume both the length of T and P will not exceed 10^6.
Output
You should output a number on a separate line,which indicates the number of valid shifts for the given text T and pattern P.
Example
matching.in聽聽聽聽聽 聽Standard Output
aaaaaa a聽聽聽聽聽聽聽聽聽 聽聽6
abababab abab聽聽 3
abcdabc abdc聽聽聽 聽0
Problem D.Exponential Form
Input:聽聽聽聽聽聽聽聽聽 聽 form.in
Output:聽聽聽聽聽聽聽聽聽Standard Output
Time limit:聽聽聽聽聽 5 second
Memory limit:聽 64 megabytes
Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
Every positive number can be presented by the exponential form.For example,
137 = 2^7 + 2^3 + 2^0
Let's present a^b by the form a(b).Then 137 is presented by 2(7)+2(3)+2(0).
Since 7 = 2^2 + 2 + 2^0 and 3 = 2 + 2^0 , 137 is finally presented by 2(2(2)+2+2(0))+2(2+2(0))+2(0).
Given a positive number n,your task is to present n with the exponential form which only contains the digits 0 and 2.
Input
The input file contains a positive integer n (n<=20000).
Output
You should output the exponential form of n an a single line.Note that,there should not be any additional white spaces in the line.
Example
form.in
137
Stardard Output
2(2(2)+2+2(0))+2(2+2(0))+2(0)
form.in
1315
Stardard Output
2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)


]]>
鍑芥暟涓湁鏈煡涓弬鏁扮殑瀹氫箟http://www.shnenglu.com/kenwell/archive/2006/03/21/4407.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Tue, 21 Mar 2006 04:39:00 GMThttp://www.shnenglu.com/kenwell/archive/2006/03/21/4407.htmlhttp://www.shnenglu.com/kenwell/comments/4407.htmlhttp://www.shnenglu.com/kenwell/archive/2006/03/21/4407.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/4407.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/4407.htmlva_arg, va_start, va_end
va_arg:
typeva_arg(
聽聽 va_listarg_ptr,
聽聽 type
);

va_arg returns the current argument; va_start and va_end do not return values

The va_arg, va_end, and va_start macros provide a portable way to access the arguments to a function when the function takes a variable number of arguments. Two versions of the macros are available: The macros defined in STDARG.H conform to the ANSI C standard, and the macros defined in VARARGS.H are compatible with the UNIX System V definition. The macros are:

The ANSI C standard macros, defined in STDARG.H, are used as follows:

  • All required arguments to the function are declared as parameters in the usual way. va_dcl is not used with the STDARG.H macros.
  • va_start sets arg_ptr to the first optional argument in the list of arguments passed to the function. The argument arg_ptr must have va_list type. The argument prev_param is the name of the required parameter immediately preceding the first optional argument in the argument list. If prev_param is declared with the register storage class, the macro's behavior is undefined. va_start must be used before va_arg is used for the first time.
  • va_arg retrieves a value of type from the location given by arg_ptr and increments arg_ptr to point to the next argument in the list, using the size of type to determine where the next argument starts. va_arg can be used any number of times within the function to retrieve arguments from the list.

The example:

//聽crt_va.c
/*聽The聽program聽below聽illustrates聽passing聽a聽variable
聽*聽number聽of聽arguments聽using聽the聽following聽macros:
聽*聽聽聽聽聽聽va_start聽聽聽聽聽聽聽聽聽聽聽聽va_arg聽聽聽聽聽聽聽聽聽聽聽聽聽聽va_end
聽*聽聽聽聽聽聽va_list聽聽聽聽聽聽聽聽聽聽聽聽聽va_dcl聽(UNIX聽only)
*/


#include聽
<stdio.h>
#define聽ANSI聽聽聽聽聽聽聽聽聽聽聽聽/*聽Comment聽out聽for聽UNIX聽version聽聽聽聽聽*/
#ifdef聽ANSI聽聽聽聽聽聽聽聽聽聽聽聽聽
/*聽ANSI聽compatible聽version聽聽聽聽聽聽聽聽聽聽*/
#include聽
<stdarg.h>
int聽average(聽int聽first,聽聽);
#else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽UNIX聽compatible聽version聽聽聽聽聽聽聽聽聽聽*/
#include聽
<varargs.h>
int聽average(聽va_list聽);
#endif

int聽main(聽void聽)
{
聽聽聽
/*聽Call聽with聽3聽integers聽(-1聽is聽used聽as聽terminator).聽*/
聽聽聽printf(聽
"Average聽is:聽%d\n",聽average(聽2,聽3,聽4,聽-1聽)聽);

聽聽聽
/*聽Call聽with聽4聽integers.聽*/
聽聽聽printf(聽
"Average聽is:聽%d\n",聽average(聽5,聽7,聽9,聽11,聽-1聽)聽);

聽聽聽
/*聽Call聽with聽just聽-1聽terminator.聽*/
聽聽聽printf(聽
"Average聽is:聽%d\n",聽average(聽-1聽)聽);
}


/*聽Returns聽the聽average聽of聽a聽variable聽list聽of聽integers.聽*/
#ifdef聽ANSI聽聽聽聽聽聽聽聽聽聽聽聽聽
/*聽ANSI聽compatible聽version聽聽聽聽*/
int聽average(聽int聽first,聽聽)
{
聽聽聽
int聽count聽=0,聽sum聽=0,聽i聽=聽first;
聽聽聽va_list聽marker;

聽聽聽va_start(聽marker,聽first聽);聽聽聽聽聽
/*聽I(yíng)nitialize聽variable聽arguments.聽*/
聽聽聽
while(聽i聽!=-1聽)
聽聽聽
{
聽聽聽聽聽聽sum聽
+=聽i;
聽聽聽聽聽聽count
++;
聽聽聽聽聽聽i聽
=聽va_arg(聽marker,聽int);
聽聽聽}

聽聽聽va_end(聽marker聽);聽聽聽聽聽聽聽聽聽聽聽聽聽聽
/*聽Reset聽variable聽arguments.聽聽聽聽聽聽*/
聽聽聽
return(聽sum聽?聽(sum聽/聽count)聽:聽0聽);
}

#else聽聽聽聽聽聽聽/*聽UNIX聽compatible聽version聽must聽use聽old-style聽definition.聽聽*/
int聽average(聽va_alist聽)
va_dcl
{
聽聽聽
int聽i,聽count,聽sum;
聽聽聽va_list聽marker;

聽聽聽va_start(聽marker聽);聽聽聽聽聽聽聽聽聽聽聽聽
/*聽I(yíng)nitialize聽variable聽arguments.聽*/
聽聽聽
for(聽sum聽=聽count聽=0;聽(i聽=聽va_arg(聽marker,聽int))聽!=-1;聽count++聽)
聽聽聽聽聽聽sum聽
+=聽i;
聽聽聽va_end(聽marker聽);聽聽聽聽聽聽聽聽聽聽聽聽聽聽
/*聽Reset聽variable聽arguments.聽聽聽聽聽聽*/
聽聽聽
return(聽sum聽?聽(sum聽/聽count)聽:聽0聽);
}

#endif


鏈涓昏鐨勬槸average 鍑芥暟
寮濮嬫椂鐢蟲槑涓涓獀a_list marker
鍚庢潵璋冪敤va_start(marker);
鍐嶅悗鏉ヨ皟鐢╲a_arg(marker, int)
鏈鍚庣粨鏉熸椂璋冪敤va_end(marker):



]]>
涓婃搗浜ゅぇ鏁版嵁緇撴瀯涓殑涓涓畻娉曢http://www.shnenglu.com/kenwell/archive/2006/03/21/4403.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Tue, 21 Mar 2006 02:55:00 GMThttp://www.shnenglu.com/kenwell/archive/2006/03/21/4403.htmlhttp://www.shnenglu.com/kenwell/comments/4403.htmlhttp://www.shnenglu.com/kenwell/archive/2006/03/21/4403.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/4403.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/4403.html

緇欏嚭涓涓墠搴忛亶鍘嗭紝緇欏嚭涓涓腑搴忛亶鍘嗭紝瑕佹眰鎶婃爲(wèi)杈撳嚭
緇欏嚭綆楁硶絳旀濡備笅錛?br />main()
{
Datatype聽preorder[n],聽inorder[n];
Struct聽link
* BT;
if (n聽 > 0 )
BT聽
= 聽creatBT( 0 ,聽n - 1 ,聽 0 ,聽n聽 - 1 );
return (BT);
}


struct 聽link * 聽createBT( int 聽prestart,聽 int 聽preend,聽 int 聽instart,聽 int 聽inend)
{
p聽
= 聽( struct 聽link * )malloc( sizeof ( struct 聽link);
p
-> lchild聽 = null ;
p
-> rchild聽 = null ;
p
-> data聽 = 聽preorder[prestart];
if (prestart聽 > 聽preend)
{聽
聽聽
for ( int 聽i聽 = 聽instart;聽inorder[i]聽 != 聽preorder[start];聽i ++ );
if (i聽 > 聽instart)
聽聽聽p
-> lchild聽 = 聽createBT(prestart聽 + 1 ,聽prestart - 聽instart聽 + 1 ,聽instart,聽i聽 - 1 );
if (i聽 < 聽inend)
聽聽p
-> rchild聽 = 聽createBT(prestart聽 - 聽instart聽 + 聽i聽 + 1 ,聽preend,聽i聽 + 1 ,聽inend);聽聽聽聽聽聽聽聽
}
聽聽

return 聽(p):
}



]]>
无码人妻精品一区二区三区久久久| 久久影视综合亚洲| 国产精品久久久久久久久鸭| 99久久免费国产特黄| 久久99热国产这有精品| 久久99精品免费一区二区| 久久久久婷婷| 久久亚洲私人国产精品| 国产国产成人精品久久| 久久人人爽人人精品视频| 一本久久a久久精品vr综合| 国产91色综合久久免费分享| 久久久久亚洲AV无码专区桃色| 天天做夜夜做久久做狠狠| 亚洲AV无码久久精品蜜桃| 91久久精品国产成人久久| 无码人妻久久一区二区三区蜜桃 | 人人妻久久人人澡人人爽人人精品 | 久久精品中文字幕第23页| 99久久精品免费看国产一区二区三区| 久久精品国产亚洲AV无码麻豆| 久久精品无码一区二区app| 日韩精品久久久久久免费| 久久精品亚洲精品国产欧美| 久久人妻少妇嫩草AV无码专区| 久久久久国产成人精品亚洲午夜| 久久夜色精品国产噜噜麻豆| 久久人人爽人人爽人人片AV东京热| 人妻无码久久一区二区三区免费| 久久伊人色| 亚洲午夜精品久久久久久人妖| 亚洲精品蜜桃久久久久久| 久久久WWW成人| 久久免费美女视频| 亚洲国产精品无码久久久秋霞2| 久久亚洲欧洲国产综合| 精品精品国产自在久久高清| 亚洲中文精品久久久久久不卡| 久久久久久无码国产精品中文字幕| 成人免费网站久久久| 久久天天躁狠狠躁夜夜躁2O2O |