代码书写规范

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <bitset>
#include "ref.h"
using namespace std;
int main()
{
    string string = "ab";
    cout << string << endl;
    system("pause");
    return 0;
}

输出:

而当输入 int int=3;则会报错

引用https://stackoverflow.com/questions/49613991/why-is-naming-a-string-variable-string-a-valid-java-construct

int is a reserved keyword. Reserved keywords may not be used as part of any formal variable name - the same is true of true, false, and null as literals. There's a list of those such keywords available.

String is a class name and cannot be a reserved keyword. This is because you cannot predict what the name of a class will be in general.

By convention, reserved keywords are lower case, variable names are camelCased, and classes are TitleCased. Following these conventions will ensure that your code doesn't run into these simple errors。

camelCased:

在英语中,依靠单词的大小写拼写复合词的做法,叫做"骆驼拼写法"(CamelCase)。比如,backColor这个复合词,color的第一个字母采用大写。

这种拼写法在正规的英语中是不允许的,但是在编程语言和商业活动中却大量使用。比如,sony公司的畅销游戏机PlayStation,play和station两个词的词首字母都是大写的。

它之所以被叫做"骆驼拼写法",是因为大小写的区分使得复合词呈现"块状"(bump),看上去就像骆驼的驼峰(hump)。

"骆驼拼写法"又分为两种。第一个词的首字母小写,后面每个词的首字母大写,叫做"小骆驼拼写法"(lowerCamelCase);第一个词的首字母,以及后面每个词的首字母都大写,叫做"大骆驼拼写法"(UpperCamelCase),又称"帕斯卡拼写法"(PascalCase)。

在历史上,"骆驼拼写法"早就存在。苏格兰人的姓名中的Mac前缀就是一例,比如著名歌手Paul MacCartney的名字中,M和C都是大写的,如果将C小写就是错误的。另一个例子是,著名化学品公司杜邦公司的名字DuPont。

但是,这种拼写法真正流行,还是在80年代以后,那时正是计算机语言开始兴起的时候。许多著名的计算机语言依靠单词不同的大小写来区分变量。在计算机语言中,还有一种"匈牙利拼写法"(Hungarian Type Notation),变量中每个单词的首字母都大写,然后变量名的最前面再加一个小写字母,表示这个单词的数据类型。比如,iMyTestValue这个变量名,就表示它是一个整数变量(integer)。据说,微软公司最喜欢使用"匈牙利拼写法"。

原文地址:https://www.cnblogs.com/likemao/p/8708447.html