0.笔记

Dev-C++软件的安装使用教程

1. C++程序的框架

//机器语言:0000111
//汇编语言:add ---> +
//高级语言:C, C++, python, java..
//编译器  -- 编辑器(IDE)

#include<iostream>  // 导入输入输出流的头文件
// # 预处理指令
// include 导入,包含
// <iostream> = input output stream 输入输出流
// 单行注释:用来解释的内容,机器不识别

/*
    多行注释1
    多行注释1
    块注释  
*/
using namespace std; // 使用名字空间 std
/*
    xxx(){ ... }  函数
    int main(){ ... } main函数,主函数,入口函数
    main函数在程序中有且仅有一个,作为程序执行的入口
    括号 () [] {} 在程序中成对出现
*/
int main(){
    cout<<"hello world"<<endl;
/*     cout 输出流
     << 流插入符号
    "hello world" 字符串,用双引号
    endl = end line, 换行
*/
    return 0;// 返回 0, 告诉操作系统,我正常结束
}
// ctrl + S   保存
// ctrl + N   新建

2. 算术运算符号

#include<iostream>
using namespace std;

int main(){
//    计算器
//   + - * /
    cout<<2147483647<<endl;
    cout<<2147483647+1<<endl;
    cout<<3<<endl;
    cout<<2 + 3<<endl;
    cout<<"2 + 3"<<endl;
    
    cout<<"2 + 3 = " <<2+3 <<endl;
    cout<<"2 - 3 = " <<2-3 <<endl;
    cout<<"2 * 3 = " <<2*3 <<endl;
    cout<<"2 / 3 = " <<2/3 <<endl;
    
    cout<<"2.0 / 3 = " <<2.0/3 <<endl;
    cout<<"2 / 3.0 = " <<2 /3.0 <<endl;
    cout<<"2.0 / 3.0 = " <<2.0/3.0 <<endl;
    
    cout<<"2 % 3 = " <<2%3 <<endl;
//    cout<<"2.0 % 3 = " <<2.0%3 <<endl; // Error
//  a/b  :若a,b均为整数,结果自动取整(舍去小数); 有一个小数,结果就是小数
//  % 取模运算符
//  a%b  :要求 a,b必为整数,结果为 a除以 b的余数。
//   2%3 = 2
//   12%3 = 0
//   2/3 = 0...2
//   12/3 = 4...0 

// ctrl + c  复制
// ctrl + v  粘贴 
    return 0;
}

3. 图形输出

#include<iostream>
using namespace std;

int main(){
    cout<<"    *"<<endl; 
    cout<<"   ***"<<endl; 
    cout<<"  *****"<<endl; 
    cout<<" *******"<<endl; 
    cout<<"*********"<<endl; 
    return 0;
}
posted @ 2024-03-02 12:07  HelloHeBin  阅读(33)  评论(0)    收藏  举报