strlen函数用于计算字符串的长度,即返回字符串中字符的个数,不包括字符串末尾的空字符’\0’。其用法如下:
#include <cstring>const char *str = "Hello, World!";int length = strlen(str);cout << "String length: " << length << endl;在上面的代码中,strlen函数将返回字符串"Hello, World!"的长度,即输出为13。
strlen函数用于计算字符串的长度,即返回字符串中字符的个数,不包括字符串末尾的空字符’\0’。其用法如下:
#include <cstring>const char *str = "Hello, World!";int length = strlen(str);cout << "String length: " << length << endl;在上面的代码中,strlen函数将返回字符串"Hello, World!"的长度,即输出为13。