#include <iostream>
#include <string>
using namespace std;
int get(const char *p);
//int get(const char p[]);//或者用数组的形式来代替
/*---------------------------------
18.31~33.char型字符串与函数
---------------------------------*/
int main()
{
//cout<<"-------C++类 empty()-----------:"<<endl;
char ch[]="hello world";//字符空间存储值是可以改变的
cout<<ch<<endl<<"the length is:"<<get(ch)<<endl;
char *p="very well";//该字符串存放在文字常量区,字符空间存储值是不可以改变的
cout<<p<<endl<<"the length is:"<<get(p)<<endl;
return 0;
}
int get(const char *p)
{
int count=0;
while(*p)
{
count++;
p++;
}
return count;
}
运行结果:
hello world
the length is:11
very well
the length is:9
Press any key to continue
C++ 字符串 11-- 18.31~33.char型字符串与函数
最新推荐文章于 2022-08-21 06:06:27 发布