1.输入的代码与c不同,c:printf;
2.科学计数法
3.C风格字符串,用数组,不能用string
#include <iostream>
using namespace std;
#define Day 7
int main() {
//输入的代码与c不同,c:printf
cout << "hello C++" << Day << "天" << endl;//hello C++7天
const double pi = 3.14;
float f1 = 3.15f;//float后加值+f
int a = 110;
cout << a << endl;
//sizeof 数据类型长度
cout << sizeof(a) << endl;
//科学计数法
float f2 = 3e3;//3*10^3
float f3 = 3e-3;//3*0.1^3
cout << f2<< f3 << endl;
//C风格字符串,用数组,不能用string
char c1[] = "aabbcc";
//C++风格字符串
string c2 = "aabbcc";
cout << c1 << " "<< c2 << endl;
system("pause");
return 0;
}
4.c++的输入
#include <iostream>
using namespace std;
int main() {
//输入
int a = 0;
cout << "给a赋值" << endl;
cin >> a;
cout << a << endl;
system("pause");
return 0;
}
5.++x,x++
6.continue语句,break语句
#include <iostream>
using namespace std;
int main() {
int a = 10;
int b = 10;
//++x,x++
int a1 = ++a * 10;//先变量+1,再表达式运算
cout << a1 << endl;//110
int b1 = b++ * 10;//先表达式运算,再变量+1
cout << b1 << endl;//100
//continue语句
for (int i = 0; i < 100; i++)
{
//如果是奇数输出,偶数不输出
if (i % 2 == 0)
{
continue;//跳过这个循环,到下一个循环
}
cout << i << endl;//输出0~100的奇数
}
cout << "****************" << endl;
//break语句
for (int j = 0; j < 100; j++)
{
//如果是奇数输出,偶数不输出
if (j % 2 == 0)
{
break;//跳出整个循环
}
cout << j << endl;//不输出
}
system("pause");
return 0;
}
7.goto语句
#include <iostream>
using namespace std;
int main() {
//goto语句
cout << "1.xxxx" << endl;
cout << "2.xxxx" << endl;
goto FLAG;
cout << "3.xxxx" << endl;
cout << "4.xxxx" << endl;
FLAG://:确认标记
cout << "5.xxxx" << endl;
system("pause");
return 0;
}
输出结果
1.xxxx
2.xxxx
5.xxxx