C++中strlen()的實現

 //編寫一個函數實現strlen的功能。
#include "iostream.h"
int strlen(char *dest)                                                                                                                                                                                                                                
{
  int n=0;
        while (*(dest++) != '\0')
                n=n+1;
  return n;
}
void main()
{
 char a[20]="wangshuang";
 cout<<a<<"長度爲:"<<" ";
 cout<<strlen(a)<<endl;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章