C++01 count cin if switch....

格式

每段代码结束都要跟随着一个 ;

输出

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

1 while

while (循环条件){
        循环体
};

当循环条件满足的时候,while循环会一直不断的循环

2 do while

do{
循环体
}while(循环条件)

do while 的特点是先循环一遍再进行循环条件判断

3 for

    for (int i = 0; i < 10; ++i) {
        std::cout << "当前循环是:" << i << std::endl;
    };

for循环,也可以用来进行遍历

扫描二维码关注公众号,回复: 10863435 查看本文章
    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;
};

猜你喜欢

转载自www.cnblogs.com/tnan/p/12715914.html
cin
今日推荐