每段代码结束都要跟随着一个 ;
std::cout << "输出内容" << std::cout;
std::cin >> 接收内容变量;
每使用一个变量都得在它使用前先定义变量类型, 如
int age;
int num = 10;
也可以使用自动推倒类型 auto
auto age = 10;
>
==
<
>=
<=
\and 也可以写为 &&
\or 也可以写为 ||
\not 也可以写为 !
c++也是支持python中的 and or not 的逻辑运算符的
while
do while
for
while (循环条件){
循环体
};
当循环条件满足的时候,while循环会一直不断的循环
do{
循环体
}while(循环条件)
do while 的特点是先循环一遍再进行循环条件判断
for (int i = 0; i < 10; ++i) {
std::cout << "当前循环是:" << i << std::endl;
};
for循环,也可以用来进行遍历
int arr[10] = { 10, 20, 3, 4, 5, 56, 17, 80, 9, 100 };
for (int i = 0; i < 10; i++){
std::cout << arr[i] << std::endl;
};
在c++中定义函数,先要在main函数前面声明函数变量, 然后再写函数体
如:
#include <iostream>
int setfor();
int main() {
setfor();
return 0;
}
int setfor(){
int arr[10] = { 10, 20, 3, 4, 5, 56, 17, 80, 9, 100 };
for (int i = 0; i < 10; i++){
std::cout << arr[i] << std::endl;
};
return 0;
};
原文:https://www.cnblogs.com/tnan/p/12715914.html