//編寫一個函數實現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;
}
C++中strlen()的實現
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
斐波那契數列的打印
#include "iostream.h" main() { int n; int a[20]={0},i; a[0]=1; a[1]=
王双
2020-07-04 18:29:40
C++繼承性和派生類的練習
王双
2020-07-04 18:29:40
運算符的重載練習
/* 讓“+”具有連接字符的功能 */ #include "iostream.h" #include "string.h" class Str
王双
2020-07-04 18:29:40
求高手指點"魔方數的輸出'的相關問題
王双
2020-02-23 18:03:17
strcat 的實現
王双
2020-02-23 18:03:17