写的第一篇博客,多有不足,慢慢进步。
strlen函数与object.size()函数,二者都是测试字符串的长度函数,前者用于C语言中的字符数组,后者用于C++的string类对象长度测试。
示例如下:
#include <iostream>
#include<climits>
#include<string>
#include<cstring>
using namespace std;
int main()
{
char ch1[20]={"0"}; //初始化
char ch2[20]={0}; //未初始化
char ch3[20]; //初始化
cout<<"The length of ch1 is :"<<strlen(ch1)<<endl;
cout<<"The length of ch1 is :"<<strlen(ch2)<<endl;
cout<<"The length of ch1 is :"<<strlen(ch3)<<endl;return 0;
}