锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一区二区日本,亚洲成在人线av,欧美大片第1页http://www.shnenglu.com/kenwell/category/1166.html鑷繁瀛︿範鎵鐢?/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++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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/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/O姣旂敤浜嬩歡閫氱煡綆鍗曞緱澶氥傚湪榪欎釜妯″瀷涓紝涓葷嚎紼嬪彧鐢ㄤ笉鍋滅殑鎺ュ彈榪炴帴鍗沖彲錛涜緟鍔╃嚎紼嬪垽鏂湁娌℃湁鏂扮殑瀹㈡埛绔繛鎺ヨ寤虹珛錛屽鏋滄湁錛屽氨涓洪偅涓鎴風濂楁帴瀛楁縺媧諱竴涓紓姝ョ殑WSARecv鎿嶄綔錛岀劧鍚庤皟鐢⊿leepEx浣跨嚎紼嬪浜庝竴縐嶅彲璀﹀憡鐨勭瓑寰呯姸鎬侊紝浠ヤ嬌寰桰/O瀹屾垚鍚嶤ompletionROUTINE鍙互琚唴鏍歌皟鐢ㄣ傚鏋滆緟鍔╃嚎紼嬩笉璋冪敤SleepEx錛屽垯鍐呮牳鍦ㄥ畬鎴愪竴嬈/O鎿嶄綔鍚庯紝鏃犳硶璋冪敤瀹屾垚渚嬬▼錛堝洜涓哄畬鎴愪緥紼嬬殑榪愯搴旇鍜屽綋鍒濇縺媧籛SARecv寮傛鎿嶄綔鐨勪唬鐮佸湪鍚屼竴涓嚎紼嬩箣鍐咃級銆?br style="line-height: normal; ">瀹屾垚渚嬬▼鍐呯殑瀹炵幇浠g爜姣旇緝綆鍗曪紝瀹冨彇鍑烘帴鏀跺埌鐨勬暟鎹紝鐒跺悗灝嗘暟鎹師灝佷笉鍔ㄧ殑鍙戦佺粰瀹㈡埛绔紝鏈鍚庨噸鏂版縺媧誨彟涓涓猈SARecv寮傛鎿嶄綔銆傛敞鎰忥紝鍦ㄨ繖閲岀敤鍒頒簡“灝鵑殢鏁版嵁”銆傛垜浠湪璋冪敤WSARecv鐨勬椂鍊欙紝鍙傛暟lpOverlapped瀹為檯涓婃寚鍚戜竴涓瘮瀹冨ぇ寰楀鐨勭粨鏋凱ER_IO_OPERATION_DATA錛岃繖涓粨鏋勯櫎浜哤SAOVERLAPPED浠ュ錛岃繕琚垜浠檮鍔犱簡緙撳啿鍖虹殑緇撴瀯淇℃伅錛屽彟澶栬繕鍖呮嫭瀹㈡埛绔鎺ュ瓧絳夐噸瑕佺殑淇℃伅銆傝繖鏍鳳紝鍦ㄥ畬鎴愪緥紼嬩腑閫氳繃鍙傛暟lpOverlapped鎷垮埌鐨勪笉浠呬粎鏄疻SAOVERLAPPED緇撴瀯錛岃繕鏈夊悗杈瑰熬闅忕殑鍖呭惈瀹㈡埛绔鎺ュ瓧鍜屾帴鏀舵暟鎹紦鍐插尯絳夐噸瑕佷俊鎭傝繖鏍風殑C璇█鎶宸у湪鎴戝悗闈粙緇嶅畬鎴愮鍙g殑鏃跺欒繕浼氫嬌鐢ㄥ埌銆?/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; ">“瀹屾垚绔彛”妯″瀷鏄縿浠婁負姝㈡渶涓哄鏉傜殑涓縐岻/O妯″瀷銆傜劧鑰岋紝鍋囪嫢涓涓簲鐢ㄧ▼搴忓悓鏃墮渶瑕佺鐞嗕負鏁頒紬澶氱殑濂楁帴瀛楋紝閭d箞閲囩敤榪欑妯″瀷錛屽線寰鍙互杈懼埌鏈浣崇殑緋葷粺鎬ц兘錛佷絾涓嶅垢鐨勬槸錛岃妯″瀷鍙傜敤浜嶹indows NT鍜學indows 2000鎿嶄綔緋葷粺銆傚洜鍏惰璁$殑澶嶆潅鎬э紝鍙湁鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忛渶瑕佸悓鏃剁鐞嗘暟鐧句箖鑷充笂鍗冧釜濂楁帴瀛楃殑鏃跺欙紝鑰屼笖甯屾湜闅忕潃緋葷粺鍐呭畨瑁呯殑CPU鏁伴噺鐨勫澶氾紝搴旂敤紼嬪簭鐨勬ц兘涔熷彲浠ョ嚎鎬ф彁鍗囷紝鎵嶅簲鑰冭檻閲囩敤“瀹屾垚绔彛”妯″瀷銆傝璁頒綇鐨勪竴涓熀鏈噯鍒欐槸錛屽亣濡傝涓篧indows NT鎴朩indows 2000寮鍙戦珮鎬ц兘鐨勬湇鍔″櫒搴旂敤錛屽悓鏃跺笇鏈涗負澶ч噺濂楁帴瀛桰/O璇鋒眰鎻愪緵鏈嶅姟錛圵eb鏈嶅姟鍣ㄤ究鏄繖鏂歸潰鐨勫吀鍨嬩緥瀛愶級錛岄偅涔圛/O瀹屾垚绔彛妯″瀷渚挎槸鏈浣抽夋嫨錛侊紙鑺傞夎嚜銆奧indows緗戠粶緙栫▼銆嬬鍏珷錛?br style="line-height: normal; ">瀹屾垚绔彛妯″瀷鏄垜鏈鍠滅埍鐨勪竴縐嶆ā鍨嬨傝櫧鐒跺叾瀹炵幇姣旇緝澶嶆潅錛堝叾瀹炴垜瑙夊緱瀹冪殑瀹炵幇姣旂敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O綆鍗曞浜嗭級錛屼絾鍏舵晥鐜囨槸鎯婁漢鐨勩傛垜鍦═鍏徃鐨勬椂鍊欐浘緇忓府鍚屼簨鍐欒繃涓涓偖浠舵湇鍔″櫒鐨勬ц兘嫻嬭瘯紼嬪簭錛岀敤鐨勫氨鏄畬鎴愮鍙fā鍨嬨傜粨鏋滆〃鏄庯紝瀹屾垚绔彛妯″瀷鍦ㄥ榪炴帴錛堟垚鍗冧笂涓囷級鐨勬儏鍐典笅錛屼粎浠呬緷闈犱竴涓や釜杈呭姪綰跨▼錛屽氨鍙互杈懼埌闈炲父楂樼殑鍚炲悙閲忋備笅闈㈡垜榪樻槸浠庝唬鐮佽璧鳳細<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.鍦ㄥ驚鐜腑錛屾垜鍋氫簡浠ヤ笅鍑犱歡浜嬫儏錛?br style="line-height: normal; ">(1).鎺ュ彈涓涓鎴風榪炴帴<br style="line-height: normal; ">(2).灝嗚瀹㈡埛绔鎺ュ瓧涓庡畬鎴愮鍙g粦瀹氬埌涓璧?榪樻槸璋冪敤CreateIoCompletionPort錛屼絾榪欐鐨勪綔鐢ㄤ笉鍚?錛屾敞鎰忥紝鎸夐亾鐞嗘潵璁詫紝姝ゆ椂浼犻掔粰CreateIoCompletionPort鐨勭涓変釜鍙傛暟搴旇鏄竴涓畬鎴愰敭錛屼竴鑸潵璁詫紝紼嬪簭閮芥槸浼犻掍竴涓崟鍙ユ焺鏁版嵁緇撴瀯鐨勫湴鍧錛岃鍗曞彞鏌勬暟鎹寘鍚簡鍜岃瀹㈡埛绔繛鎺ユ湁鍏崇殑淇℃伅錛岀敱浜庢垜浠彧鍏沖績濂楁帴瀛楀彞鏌勶紝鎵浠ョ洿鎺ュ皢濂楁帴瀛楀彞鏌勪綔涓哄畬鎴愰敭浼犻掞紱<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; ">鎴戜細浠庝互涓嬪嚑涓柟闈㈡潵榪涜姣旇緝<br style="line-height: normal; ">*鏈夋棤姣忕嚎紼?4榪炴帴鏁伴檺鍒?br style="line-height: normal; ">濡傛灉鍦ㄩ夋嫨妯″瀷涓病鏈夐噸鏂板畾涔塅D_SETSIZE瀹忥紝鍒欐瘡涓猣d_set榛樿鍙互瑁呬笅64涓猄OCKET銆傚悓鏍風殑錛屽彈MAXIMUM_WAIT_OBJECTS瀹忕殑褰卞搷錛屼簨浠墮夋嫨銆佺敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O閮芥湁姣忕嚎紼嬫渶澶?4榪炴帴鏁伴檺鍒躲傚鏋滆繛鎺ユ暟鎴愬崈涓婁竾錛屽垯蹇呴』瀵瑰鎴風濂楁帴瀛楄繘琛屽垎緇勶紝榪欐牱錛屽娍蹇呭鍔犵▼搴忕殑澶嶆潅搴︺?br style="line-height: normal; ">鐩稿弽錛屽紓姝ラ夋嫨銆佺敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營/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; ">闄や簡寮傛閫夋嫨浠ュ錛屽叾浠栨ā鍨嬭嚦灝戦渶瑕?涓嚎紼嬨備竴涓富綰跨▼鍜屼竴涓緟鍔╃嚎紼嬨傚悓鏍風殑錛屽鏋滆繛鎺ユ暟澶т簬64錛屽垯閫夋嫨妯″瀷銆佷簨浠墮夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/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/O<浜嬩歡閫夋嫨<瀹屾垚绔彛<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營/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鍑芥暟榪斿洖鍚庤繕瑕侀拡瀵規墍鏈夊鎺ュ瓧榪涜閫愪竴嫻嬭瘯錛屾垜鐨勬劅瑙夋槸鏁堢巼姣旇緝宸紱瀹屾垚绔彛鍜岀敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營/O鍩烘湰涓婁笉娑夊強鍏ㄥ眬鏁版嵁錛屾晥鐜囧簲璇ユ槸鏈楂樼殑錛岃屼笖鍦ㄥ澶勭悊鍣ㄦ儏褰笅瀹屾垚绔彛榪樿楂樹竴浜涳紱浜嬩歡閫夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O鍦ㄥ疄鐜版満鍒朵笂閮芥槸閲囩敤WSAWaitForMultipleEvents錛屾劅瑙夋晥鐜囧樊涓嶅錛涜嚦浜庡紓姝ラ夋嫨錛屼笉濂芥瘮杈冦傛墍浠ユ垜鐨勭粨璁烘槸:閫夋嫨<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營/O<浜嬩歡閫夋嫨<鐢ㄥ畬鎴愪緥紼嬪疄鐜扮殑閲嶅彔I/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++ 瀛︿範</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++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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[     鎽樿: 鏈枃綆鍗曚粙緇嶄簡褰撳墠Windows鏀寔鐨勫悇縐峉ocket I/O妯″瀷錛屽鏋滀綘鍙戠幇鍏朵腑瀛樺湪浠涔堥敊璇鍔″繀璧愭暀銆備竴錛歴elect妯″瀷浜岋細WSAAsyncSelect妯″瀷涓夛細WSAEventSelect妯″瀷鍥涳細Overlapped I/O 浜嬩歡閫氱煡妯″瀷浜旓細Overlapped I/O 瀹屾垚渚嬬▼妯″瀷鍏細IOCP妯″瀷鑰侀檲鏈変竴涓湪澶栧湴宸ヤ綔鐨勫コ鍎匡紝涓嶈兘緇忓父鍥炴潵錛岃侀檲鍜屽ス閫氳繃淇′歡鑱旂郴銆備粬浠殑淇′細琚偖閫掑憳鎶曢掑埌浠栦滑鐨?..  <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++ 瀛︿範</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++ 瀛︿範c++ 瀛︿範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鍛戒護琛屼慨鏀圭綉緇滈厤緗柟娉?/title><link>http://www.shnenglu.com/kenwell/archive/2008/07/22/56832.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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="hvzpftn" class="postentry"> <p>/etc/network/interfaces<br>鎵撳紑鍚庨噷闈㈠彲璁劇疆DHCP鎴栨墜鍔ㄨ緗潤鎬乮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>鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<br><font face="鏂板畫浣?><code>sudo /etc/init.d/networking restart</code><br></font>涔熷彲浠ュ湪鍛戒護琛屼笅鐩存帴杈撳叆涓嬮潰鐨勫懡浠ゆ潵鑾峰彇鍦板潃</p> <p><font face="鏂板畫浣?><code>sudo dhclient eth0</code><br></font><strong><br>2. 涓虹綉鍗¢厤緗潤鎬両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鍦板潃絳変俊鎭崲鎴愪綘鑷繁灝卞彲浠ヤ簡.鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<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>鏍規嵁浣犵殑鎯呭喌濉笂鎵鏈夎濡俛ddress,netmask,network,broadcast鍜実ateways絳変俊鎭?<br>鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<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>緋葷粺鍚姩鏃?瀹冧細浠?etc/hostname鏉ヨ鍙栦富鏈虹殑鍚嶇О.</p> <p>鍏充簬璁劇疆涓繪満鍚嶇О鐨勬洿澶氫俊鎭?璇瘋闂?a target="_blank"><font color="#0000ff">榪欓噷</font></a></p> <p><strong>5. 閰嶇疆DNS</strong></p> <p>棣栧厛,浣犲彲浠ュ湪/etc/hosts涓姞鍏ヤ竴浜涗富鏈哄悕縐板拰榪欎簺涓繪満鍚嶇О瀵瑰簲鐨処P鍦板潃,榪欐槸綆鍗曚嬌鐢ㄦ湰鏈虹殑闈欐佹煡璇?</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="hvzpftn" class="postentry"> <p>/etc/network/interfaces<br>鎵撳紑鍚庨噷闈㈠彲璁劇疆DHCP鎴栨墜鍔ㄨ緗潤鎬乮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>鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<br><font face="鏂板畫浣?><code>sudo /etc/init.d/networking restart</code><br></font>涔熷彲浠ュ湪鍛戒護琛屼笅鐩存帴杈撳叆涓嬮潰鐨勫懡浠ゆ潵鑾峰彇鍦板潃</p> <p><font face="鏂板畫浣?><code>sudo dhclient eth0</code><br></font><strong><br>2. 涓虹綉鍗¢厤緗潤鎬両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鍦板潃絳変俊鎭崲鎴愪綘鑷繁灝卞彲浠ヤ簡.鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<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>鏍規嵁浣犵殑鎯呭喌濉笂鎵鏈夎濡俛ddress,netmask,network,broadcast鍜実ateways絳変俊鎭?<br>鐢ㄤ笅闈㈢殑鍛戒護浣跨綉緇滆緗敓鏁?<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>緋葷粺鍚姩鏃?瀹冧細浠?etc/hostname鏉ヨ鍙栦富鏈虹殑鍚嶇О.</p> <p>鍏充簬璁劇疆涓繪満鍚嶇О鐨勬洿澶氫俊鎭?璇瘋闂?a target="_blank"><font color="#0000ff">榪欓噷</font></a></p> <p><strong>5. 閰嶇疆DNS</strong></p> <p>棣栧厛,浣犲彲浠ュ湪/etc/hosts涓姞鍏ヤ竴浜涗富鏈哄悕縐板拰榪欎簺涓繪満鍚嶇О瀵瑰簲鐨処P鍦板潃,榪欐槸綆鍗曚嬌鐢ㄦ湰鏈虹殑闈欐佹煡璇?</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++ 瀛︿範</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++ 瀛︿範c++ 瀛︿範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;
        
//鍚庨潰灝辨槸瀵規嬁鍥炴潵鐨剎ml鏁版嵁榪涜瑙f瀽錛屼富瑕佹槸dom鏂規硶
    }
    
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++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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++ 瀛︿範</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++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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[緇欏涔燾++鐨勬柊鎵嬶紝榪欎簺涔︾睄閮芥槸寰堢粡鍏哥殑銆傜粡鍏鎬腑鐨勭粡鍏?br>娣卞害鎺㈢儲C++瀵硅薄妯″瀷<br>鑻辨枃鐗?http://www.nengxia.com/soft.asp?id=5<br>涓枃鐗堬細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>絎竴鍗鳳細<br>涓枃鐗?http://www.nengxia.com/soft.asp?id=1039<br>鑻辨枃鐗堬細 Prentice Hall Bruce Eckel Thinking In C++, Second EditionVolume.1<br>絎簩鍗鳳細<br>涓枃鐗堬細http://www.nengxia.com/soft.asp?id=1040<br>鑻辨枃鐗堬細http://www.nengxia.com/soft.asp?id=1041<br><br><br>c++ Programming language <br>涓枃鐗堬細http://www.nengxia.com/soft.asp?id=1038<br>鑻辨枃鐗堬細http://www.nengxia.com/soft.asp?id=368 <br><br>C++ Primer<br>絎笁鐗堜腑鏂囩増錛歨ttp://www.nengxia.com/soft.asp?id=6<br>絎洓鐗?br>鑻辨枃鐗堬細http://www.nengxia.com/soft.asp?id=117<br>涓枃鐗堬細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 絎?鐗堜腑鏂囷細<br>涓枃鐗堬細http://www.nengxia.com/soft.asp?id=987<br>鑻辨枃鐗堬細<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>涓枃鐗堬細http://www.nengxia.com/soft.asp?id=9<br>鑻辨枃鐗堬細http://www.nengxia.com/soft.asp?id=1033<br><br>More Effective C++<br>涓枃鐗堬細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>鑻辨枃鐗堬細<br>http://www.nengxia.com/soft.asp?id=1034<br>綆浣撲腑鏂囩増錛?br>http://www.nengxia.com/soft.asp?id=15<br>綣佷綋涓枃鐗堬細<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>涓枃鐗堬細http://www.nengxia.com/soft.asp?id=1035<br>鑻辨枃鐗堬細http://www.nengxia.com/soft.asp?id=18<br><br>More Excetption c++<br>鑻辨枃鐗堬細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>鑻辨枃鐗堬細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++ 瀛︿範</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騫村璇曚笂鏈洪 (杞級http://www.shnenglu.com/kenwell/archive/2006/03/31/4862.htmlc++ 瀛︿範c++ 瀛︿範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鏈鐩槸鎳掔尓涓瀛椾竴瀛楁暡涓婄數鑴戠殑錛岃漿杞借灝婇噸鎳掔尓鐨勫姵鍔ㄦ垚鏋滐紝娉ㄦ槑杞嚜鎳掔尓鐨勭獫紿?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++ 瀛︿範c++ 瀛︿範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聽);聽聽聽聽聽
/*聽Initialize聽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聽);聽聽聽聽聽聽聽聽聽聽聽聽
/*聽Initialize聽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++ 瀛︿範c++ 瀛︿範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

緇欏嚭涓涓墠搴忛亶鍘嗭紝緇欏嚭涓涓腑搴忛亶鍘嗭紝瑕佹眰鎶婃爲杈撳嚭
緇欏嚭綆楁硶絳旀濡備笅錛?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):
}



]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            最新亚洲视频| 亚洲一区二区在| 欧美理论在线| 久久综合久久综合久久| 欧美精品乱人伦久久久久久| 久久亚洲私人国产精品va| 国产九色精品成人porny| 亚洲国产精品va在线观看黑人| 国产精品日韩| 一区二区三区国产在线观看| 亚洲精品乱码久久久久| 久久久久久久久伊人| 久久国产精品一区二区三区| 国产精品国产三级国产专播品爱网 | 国内精品久久久| 亚洲一区二区三区四区五区黄| 亚洲国内在线| 久久婷婷国产麻豆91天堂| 久久久久久夜精品精品免费| 国产伦精品一区| 亚洲制服少妇| 久久成人一区| 国产一区在线视频| 久久精品99国产精品| 久久精品一区蜜桃臀影院| 国产日韩亚洲| 欧美伊人久久| 久色婷婷小香蕉久久| 一区免费观看视频| 久久综合中文| 亚洲国产高清aⅴ视频| 亚洲精选在线| 欧美日韩亚洲综合一区| 一区二区毛片| 欧美一级久久久| 国产专区欧美精品| 裸体歌舞表演一区二区| 亚洲黄色小视频| 亚洲午夜激情网站| 国产精品视频福利| 欧美一区二区三区在| 欧美色欧美亚洲高清在线视频| 一区二区成人精品| 久久久福利视频| 精品电影在线观看| 欧美精品成人| 欧美亚洲一区在线| 欧美成人精品| 亚洲四色影视在线观看| 国产日韩一区二区三区在线播放| 欧美一区免费| 亚洲人精品午夜在线观看| 亚洲综合国产激情另类一区| 国产亚洲aⅴaaaaaa毛片| 久久久噜噜噜久久中文字免| 亚洲精品乱码视频| 久久精品论坛| 亚洲欧美在线观看| 欧美xx视频| 亚洲一区二区在线视频| 在线免费观看成人网| 欧美三区在线| 久久久在线视频| 在线综合亚洲欧美在线视频| 亚洲国产高清自拍| 久久综合成人精品亚洲另类欧美| 亚洲人体影院| 久久亚洲综合网| 亚洲一级免费视频| 亚洲福利视频在线| 国产精品视频观看| 欧美美女福利视频| 久久久蜜桃精品| 亚洲午夜影视影院在线观看| 欧美成人a视频| 欧美在线日韩精品| 中文日韩在线| 最新日韩欧美| 欧美风情在线观看| 欧美在线网址| 亚洲制服欧美中文字幕中文字幕| 亚洲国产色一区| 久久久久综合一区二区三区| 亚洲欧美国产高清va在线播| 亚洲伦理在线观看| 在线精品在线| 国产一区二区三区四区在线观看| 欧美日韩一区二区三区四区在线观看| 久久久久一区二区| 香蕉久久一区二区不卡无毒影院 | 亚洲欧美在线一区| 一区二区av在线| 亚洲三级电影全部在线观看高清| 久久一区国产| 久久久青草青青国产亚洲免观| 亚洲一区二区三区精品在线| 日韩一级欧洲| 99精品视频免费在线观看| 亚洲精华国产欧美| 亚洲人成毛片在线播放女女| 亚洲高清自拍| 亚洲国产导航| 亚洲日本久久| 亚洲精品小视频在线观看| 亚洲国产小视频| 亚洲欧洲日产国产综合网| 91久久精品国产91久久性色tv| 在线电影国产精品| 亚洲第一久久影院| 亚洲欧洲精品一区二区三区 | 欧美在线一级视频| 欧美一区二区黄| 久久99伊人| 久久综合色影院| 欧美成人性生活| 亚洲国产网站| 99亚洲精品| 亚洲欧美成人精品| 久久免费观看视频| 欧美成人免费全部| 欧美日韩在线播放一区二区| 国产精品成人一区二区网站软件| 国产精品久久久久久久久久久久久| 国产精品高潮粉嫩av| 国产深夜精品| 亚洲电影在线观看| 欧美大秀在线观看| 欧美日韩免费在线视频| 国产精品久久久久久久久免费桃花 | 欧美亚洲第一区| 国产精品一区二区三区免费观看| 国产一区二区电影在线观看| 在线成人免费观看| 一区二区三区视频在线| 香港久久久电影| 麻豆九一精品爱看视频在线观看免费| 欧美激情a∨在线视频播放| 亚洲精品美女久久7777777| 一区二区三区视频在线播放| 欧美一区二区女人| 欧美激情视频一区二区三区免费| 国产精品国产a级| 激情小说亚洲一区| 在线亚洲观看| 久久性天堂网| av72成人在线| 久久综合九色综合久99| 国产精品成人一区二区艾草| 一区二区三区自拍| 亚洲免费影视| 欧美黑人多人双交| 午夜精品久久久久影视| 欧美成人免费网站| 国产性色一区二区| 亚洲综合日本| 亚洲国产99精品国自产| 香蕉av福利精品导航| 欧美日本中文| 在线国产亚洲欧美| 翔田千里一区二区| 亚洲精品影视在线观看| 久久久久久久波多野高潮日日| 欧美视频导航| 日韩天堂在线视频| 免费视频亚洲| 性欧美在线看片a免费观看| 欧美精品亚洲二区| 亚洲国产成人av好男人在线观看| 欧美一区二区高清| 一级日韩一区在线观看| 欧美大尺度在线观看| 黄色亚洲在线| 久久精品视频免费观看| 亚洲午夜精品国产| 欧美日韩国产色站一区二区三区| 伊大人香蕉综合8在线视| 久久国产精品一区二区三区四区 | 久久免费视频网站| 国产又爽又黄的激情精品视频| 亚洲欧美99| 宅男噜噜噜66国产日韩在线观看| 欧美激情在线播放| 亚洲精品专区| 亚洲激情女人| 欧美国产日本在线| 日韩视频在线你懂得| 亚洲第一页自拍| 欧美mv日韩mv国产网站| 亚洲激情电影中文字幕| 欧美a级在线| 免费观看在线综合色| 亚洲国产人成综合网站| 欧美二区在线| 欧美精品日韩一本| 中文精品99久久国产香蕉| 夜夜嗨av一区二区三区免费区| 欧美日韩八区| 亚洲欧美视频在线| 亚洲欧美日本伦理| 黄色欧美日韩|