#include <iostream>
using namespace std;
int main()
{
int i,j; // 定义2个整型变量,用于存放两个字符的ASCII码值
i = 'A'; // 将一个字符常量赋给整型变量i
j = 'B'; // 将一个字符常量赋给整型变量j
cout << i << " " << j << endl;
return 0;
}
// 字符串小写转换为大写
#include <iostream>
using namespace std;
int main()
{
char c1,c2;
c1 = 'a';
c2 = 'b';
c1 -= 32;
c2 -= 32;
cout << c1 << " " << c2 << endl;
return 0;
}
C++变量名命名规则:只能由字母、数字、下划线构成,且第一个字母必须为字母or下划线
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string str = "China";
for(int i = 0; str[i]; i++)
{
str[i] += 4;
}
for(int i = 0; str[i]; i++)
{
cout << str[i] << " ";
}
return 0;
}