首页 > 编程语言 > 详细

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

时间:2020-04-16 23:17:34      阅读:68      评论:0      收藏:0      [点我收藏+]

格式

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

输出

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循环,也可以用来进行遍历

    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;
};

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

原文:https://www.cnblogs.com/tnan/p/12715914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!