C/C++ strlen函数
计算字符串长度的函数。
下面给出的是百度百科的一段代码
https://baike.baidu.com/item/strlen/2737?fr=aladdin
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
char s[10000]="Hello, World!";
cout << s << "has" << strlen(s) << "character(s)." << endl;
//printf("%s has %d character(s).",s,strlen(s));
//getchar();
return 0;
}
运行结果:Hello, World! has 13 character(s).
区分于sizeof()
char str[20000]="0123456789";
long a=strlen(str); //a=10;
int b=sizeof(str); //而b=20000;