1.C++代码格式与语法基础—HelloWorld.
#include<bits/stdc++.h> //使用万能头文件
using namespace std; //使用命名空间std
int main() //main函数是C++中内置的启动函数,也就是程序入口
{
cout << "Hello,World!" << endl; //利用cout将字符串输出,字符串用双引号括起
printf("Hello,World!"); //利用printf将字符串输出
return 0; //函数遇到 return 会立刻结束 返回0表示main函数正常结束
}
输出结果:
Hello,World!
Hello,World!
2.C++代码格式与语法基础—基本数据类型
#include<bits/stdc++.h> //使用万能头文件
using namespace std; //使用命名空间std
int main() //main函数是C++中的内置函数 也就是程序入口
{
int x = 3; //整数x
double d = 3.14; //浮点数(小数)d
char ch = 'A'; //字符ch
char s[] = "Hello"; //字符串s
bool b = true; //布尔值(即真假值)b
cout <