• C++基础一初始化


    #include <iostream>
    
    #include <string>
    
    using namespace std;
    
     
    
    //单行 注释
    
    /*多行注释*/
    
     
    
     
    
    //常量定义
    
    #define Month 12;
    
    #define Day  31;
    
    /*main为c++的入口函数*/
    
    int main()
    
    {
    
    //变量定义
    
    char b = 'B';
    
    int a = 10;
    
    const int hours = 24;
    
    const bool flags = true;
    
     
    
    cout << "hello world " << endl;
    
    cout << "a = " << a << endl; 
    
    cout << "b = " << b << endl;
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
     
    
    float second = 60.0009f; // 单精度浮点
    
     
    
    cout << "年份 ="<< Day;
    
    cout << "月份 =" << Month;
    
    cout << "小时 =" << hours;
    
    cout << "
    "; 
    
    cout << "one minute has " <<second << " s";
    
    cout << "
    ";
    
    cout << "";
    
    cout << "";
    
    int Times = hours *  Month;
    
    cout << "Month * Hours ==" << Times;
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
     
    
    //sizeof关键字:统计字节数
    
    cout << "short占空间:" << sizeof(short);
    
    cout << "int占空间:" << sizeof(int); 
    
    cout << "long占空间:" << sizeof(long);
    
    cout << "long long 占空间:" << sizeof(long long);
    
    cout << "Month 占空间:" << sizeof Month;
    
    cout << "second占空间:" << sizeof second;
    
    cout << "char 占空间:" << sizeof(char);
    
    cout << "
    ";
    
    cout << "
    ";
    
    cout << "
    ";
    
     
    
    //字符型
    
    char ch = 'a'; //只能有一个变量,单引号
    
    cout << ch << endl;
    
    cout << sizeof ch << endl;
    
    cout << int(ch) << endl; //字符串转换为ASCII码值
    
     
    
     
    
    //字符串型
    
    char s1[] = "this is that ";//C >字符数组,双引号
    
    string s2 = "this is not";//C++ >字符数组,双引号。头文件标识#include <string>
    
    cout << s1 << endl;
    
    cout << s2 << endl;
    
     
    
    //布尔类型
    
    bool flag = true;
    
    bool unflag = false;
    
    cout << flag << endl; //0
    
    cout << unflag << endl; //1
    
    cout << sizeof flag << endl;
    
     
    
    /*
    
    //cin 数据输入:从键盘获取输入
    
    int mya = 0;
    
    cout <<"How old are u ? " << endl;
    
    cin >> mya;
    
    cout << "U are " << mya<<" years old "<<endl;
    
    string talk = "";
    
    cout << "What did u say?" << endl;
    
    cin >> talk;
    
    cout << "U said :" << talk << endl;
    
    cout << "
    " << endl;
    
    cout << "
    " << endl;
    
    cout << "
    " << endl;
    
    */
    
     
    
     
    
     
    
    //运算符
    
    int a1 = 10;
    
    int a2 = 20;
    
    int a1_a2 = a1 + a2;
    
    cout << a1_a2 << endl;
    
     
    
     
    
     
    
    //递增运算符
    
    int a1 = 30;
    
    a1++;
    
    cout << a << endl;
    
     
    
    system("pause");
    
    return 0;
    
     
    
     
  • 相关阅读:
    『Argparse』命令行解析
    『MXNet』专题汇总
    用.NET开发通用Windows App
    ASP.NET 5探险(6):升级ASP.NET 5到beta6
    使用ASP.NET MVC、Rabbit WeixinSDK和Azure快速开发部署微信后台
    Visual Studio 2015将在7月20号RTM
    VS2015上又一必备免费插件:Refactoring Essentials
    ASP.NET 5探险(5):利用AzureAD实现单点登录
    Visual Studio Code升级到0.5,提供对ES6的更好支持
    ASP.NET 5探险(4):如何把ASP.NET 5从beta4升级到beta5
  • 原文地址:https://www.cnblogs.com/cou1d/p/14209029.html
Copyright © 2020-2023  润新知