栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C过渡到C++

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C过渡到C++

#include  //input output stream 输入输出流
using namespace std;//使用std 的名称空间,cin cout在其中,也可在cincout    前加std::
#include

int main()
{
    cout << "hello world" << endl; //end of line换行
    int a = 10;
    cout << "a=" << a << endl;
    cout << a << endl;

    cout << "a所占内存空间为:" << sizeof(a) << endl;
    cout << "int所占内存空间为:" << sizeof(int) << endl;
    cout << "int*所占内存空间为:" << sizeof(int*) << endl;

    //转义字符  n--换行符  \--反斜杠  t--水平制表符
    cout << "\" << endl;
    cout << "abcdthahaha" << endl; //具有对齐效果
    cout << "abthahaha" << endl;

    //字符串风格 string类
    char arr[] = "abcde";
    string brr = "abcde";
    cout << arr << endl;
    cout << brr << endl;
    cout << arr + brr << endl;//可以相加

    //bool数据类型(1字节);true--真(非0) false--假(0)
    bool flag1 = true;
    bool flag2 = false;
    cout << flag1 << endl;
    cout << flag2 << endl;
    cout << sizeof(bool) << endl;

    //地址
    int crr[5] = { 1,2,3,4,5 };
    cout << crr << endl;
    cout << &crr[0] << endl;
    cout << (int)crr << endl;

    //new 在堆区开辟数据
    int *p = new int(10);
    cout << *p << endl;
    delete p;
    p = NULL;

    int* pa = new int[10];
    for (int i = 0; i < 10; i++)
        pa[i] = i + 100;
    for (int i = 0; i < 10; i++)
        cout << pa[i] << endl;
    delete[] pa;

    //引用:给变量起别名  数据类型 &别名=原名
    int i = 10;
    int& j = i;  //引用必须初始化,且初始化后不可更改
    cout << j << endl;
    j = 11;
    cout << i << endl;
  //int &a=10;--error
  //const int &a;--ok--会自动生成临时变量int tmp=10;const int &a=tmp;

    //C++的数据输入
    string w = "adsdf";
    bool h = false;

    cout << "nn给布尔类型h赋值" << endl;
    cin >> h;
    cout << h << endl;    //只要是非0值都代表真

    system("pause");
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/864364.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号