骆驼式命名法(Camel-Case)又称驼峰式命名法,是电脑程式编写时的一套命名规则(惯例)。正如它的名称CamelCase所表示的那样,是指混合使用大小写字母来构成变量和函数的名字。程序员们为了自己的代码能更容易的在同行之间交流,所以多采取统一的可读性比较好的命名方式。
利用字符串来编写驼峰命名法的代码:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string e;
int n,m=0;
char a[1000];
scanf("%s",a);
int i=strlen(a);
for(int t=0;t<i;t++)
{
if((int)a[t]>64&&(int)a[t]<91)
{
if(t!=0)
{
a[t]=a[t]+' ';
cout<<" "<<a[t];
}
else
{
a[t]=a[t]+' ';
cout<<a[t];
}
}
else
cout<<a[t];
}
}
其中在大写字母面前添加空格,且将所有大写字母变为小写字母。
运行实例: