自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

對C++手冊內(nèi)容簡介

開發(fā) 后端
C++作為一種語言,大多數(shù)的人都是把它默認(rèn)為面向?qū)ο蟮闹С?,認(rèn)為他就是C語言的替代品,一種延伸而已,而事際上,C++與C是完全不同的語言,下面學(xué)一下C++手冊相關(guān)內(nèi)容。

學(xué)無止境,最近學(xué)習(xí)了C++手冊的一些知識,寫了二段代碼.希望有人來點(diǎn)評,指出其中的錯誤,或需要改進(jìn)的地點(diǎn).在寫的過程當(dāng)中,遇到很多問題,不段的問人,在貼求助。

查看C++手冊,查看網(wǎng)上教程才得以寫出. 但C++的許多基礎(chǔ)知識我還是不懂.并不段的在學(xué)習(xí).  由于工作繁忙,學(xué)習(xí)進(jìn)度實(shí)在是小得可憐,發(fā)了很多C++語言的基礎(chǔ).在那里我學(xué)到了許多知識. 如果打算學(xué)習(xí)C++手冊的成員們就一起吧。

  1. #include <stdlib.h>    
  2. #include <stdio.h>    
  3. #include <errno.h>    
  4. #include <string.h>    
  5. #include <netdb.h>    
  6. #include <sys/types.h>    
  7. #include <netinet/in.h>    
  8. #include <sys/socket.h>    
  9. #include <syslog.h>    
  10. #include <unistd.h>     
  11. #include <netinet/in.h>      
  12. #include <sys/socket.h>        
  13. #include <arpa/inet.h>        
  14. #include <errno.h>    
  15. #include <sys/ipc.h>        
  16. #include <sys/shm.h>    
  17. /*建立精靈進(jìn)程*/    
  18. int daemon_init(void)    
  19. { pid_t pid;    
  20. if((pid = fork()) < 0) return(-1);    
  21. else if(pid != 0) exit(0); /* parent exit */    
  22. /* child continues */    
  23. setsid(); /* become session leader */    
  24. chdir("http://tmp"); /* change working directory */    
  25. umask(0); /* clear file mode creation mask */    
  26. close(0); /* close stdin */    
  27. close(1); /* close stdout */    
  28. close(2); /* close stderr */    
  29. return(0); }    
  30. /*讀取文件數(shù)據(jù)*/    
  31. void myread(char *buff)    
  32. {    
  33. char buf[1024];    
  34. FILE *fp;    
  35. fp = fopen("/proc/net/dev", "r");    
  36. if(!fp)    
  37.  {    
  38. perror("fopen");    
  39. exit(2);    
  40. }    
  41. fgets(buf, 1024, fp);    
  42. fgets(buf, 1024, fp);    
  43. fgets(buf, 1024, fp);    
  44. fgets(buf, 1024, fp);    
  45. fscanf(fp, "%s", buf);   /*從第三行開始讀*/    
  46. snprintf(buff, 100, "%s", buf);    
  47. fclose(fp);    
  48. printf("%s\n", buf);    
  49. }    
  50.     
  51. int main(int argc, char *argv[])    
  52. {    
  53. int sockfd,new_fd;     
  54. struct sockaddr_in server_addr;    
  55. struct sockaddr_in client_addr;    
  56. int sin_size,portnumber;    
  57. char hello[1024];    
  58. /* 服務(wù)器端開始建立socket描述符 */    
  59. if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)    
  60. {    
  61. printf("Socket error:%s\n\a",strerror(errno));    
  62. exit(1);    
  63. }    
  64. /* 服務(wù)器端填充 sockaddr_in結(jié)構(gòu) */    
  65. bzero(&server_addr,sizeof(struct sockaddr_in));    
  66. server_addr.sin_family=AF_INET;    
  67. server_addr.sin_addr.s_addr=inet_addr("本機(jī)IP");        
  68. server_addr.sin_port=htons(10240); /*端口號轉(zhuǎn)換為網(wǎng)絡(luò)字節(jié)序*/    
  69. /* 捆綁sockfd描述符 */    
  70. if(bind(sockfd,(struct sockaddr *)(&server_addr),sizeof(struct sockaddr))==    
  71. -1)    
  72. {    
  73. printf("Bind error:%s\n\a",strerror(errno));    
  74. exit(1);    
  75. }    
  76. /* 監(jiān)聽sockfd描述符 */    
  77. if(listen(sockfd,5)==-1) /*5為請求隊列的***請求數(shù)*/    
  78. {    
  79. printf("Listen error:%s\n\a",strerror(errno));    
  80. exit(1);    
  81. }    
  82. while(1)    
  83. {    
  84. /* 服務(wù)器阻塞,直到客戶程序建立連接 */    
  85. sin_size=sizeof(struct sockaddr_in);    
  86. if((new_fd=accept(sockfd,(struct sockaddr *)(&client_addr),&sin_size    
  87. ))==-1)    
  88. {    
  89. printf("Accept error:%s\n\a",strerror(errno));    
  90. exit(1);    
  91. }    
  92. /*inet_ntoa的作用是將一個32位Ipv4地址轉(zhuǎn)換為相應(yīng)的點(diǎn)分十進(jìn)制數(shù)串*/    
  93. printf("Server get connection from %s\n",inet_ntoa(client_addr.sin_addr));    
  94. /*向客戶端發(fā)送hello字符數(shù)組的內(nèi)容*/    
  95. myread(hello);    
  96. if(write(new_fd,hello,strlen(hello))==-1)    
  97. {    
  98. printf("Write Error:%s\n",strerror(errno));    
  99. exit(1);    
  100. }    
  101. /* 這個通訊已經(jīng)結(jié)束 */    
  102. close(new_fd);    
  103. }/* while結(jié)尾處*/    
  104. close(sockfd);    
  105. exit(0);    
  106. }   

【編輯推薦】

  1. C與C++中標(biāo)準(zhǔn)輸入實(shí)現(xiàn)方式上的一點(diǎn)區(qū)別
  2. C++編譯器如何對Const常量進(jìn)行分配存儲空間
  3. C++類庫設(shè)計的基本構(gòu)思與方法
  4. 玩轉(zhuǎn)C++語言的幾種方法
  5. 如何更好的進(jìn)行C++代碼編制
責(zé)任編輯:chenqingxiang 來源: 新浪科技
相關(guān)推薦

2013-04-09 15:49:04

iOSSQLite基礎(chǔ)內(nèi)容簡

2010-07-13 09:02:16

Perl

2010-04-26 09:51:54

Oracle OCP

2010-03-03 15:26:54

Python編碼規(guī)范

2010-01-18 16:27:26

C++語言

2010-01-14 17:18:17

C++語言

2010-03-15 13:35:25

Python GUI

2010-04-07 10:51:19

Oracle客戶

2010-01-13 17:04:36

C++語言

2010-01-18 15:40:37

Visual C++工

2018-09-25 23:15:12

Office 應(yīng)用微軟

2010-01-15 15:52:18

CC++

2010-01-15 10:41:06

CC++

2010-01-28 15:09:36

C++資源管理

2010-01-13 18:34:43

C++ 托管

2010-01-18 10:53:26

2010-02-06 11:13:11

C++ makefil

2010-02-06 14:12:54

C++繼承方式

2010-02-05 15:04:41

C++定義變量

2010-01-25 18:19:17

C++特性
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號