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

C++11简单练习

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

C++11简单练习

#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

std::map DataMap = {{1, 2}, {3, 4}};

int main(int argv, char* argc[])
{
    char szBuffer[3] = {0};
    strncpy(szBuffer, "ab", 2);
    char szTmp[3] = {0};
    szTmp[0] = szBuffer[0] >> 2;

    auto a = 10;
    auto b = "abc";
    auto c = "def";
    //auto d = b + c;
    auto e = 20;
    auto f = a + e;
    printf("f:%d, d:%sn", f, b);


    //istd::map DataMap = {{1, 2}, {3, 4}};
    //printf("map:%d, %dn)
    for (auto d : DataMap)
    {
        cout << d.first << endl;
        cout << d.second << endl;
    }

    auto func = [&b](){
        b = "aabc";
        //cout << b < DataVec;
    DataVec.push_back(1);
    DataVec.push_back(2);
    DataVec.push_back(3);

    for (auto &tmp : DataVec)
    {
        tmp = 1;
        //cout << tmp << endl;
    }

    for (auto tmp : DataVec)
    {
        cout << tmp << endl;
    }

    //array save stack
    array arr = {"v", "b", "n", "m"};
    for (auto tmp : arr)
    {
        cout << tmp << endl;
    }

    auto ptr = make_shared(10);
    cout << ptr.use_count() << endl;

    {
        shared_ptr ptr1 = ptr;
        cout << ptr1.use_count() << endl;
        cout << ptr.use_count() << endl;
    }
    cout << ptr.use_count() << endl;

    unique_ptr ptr2(new int(10));
    //auto ptr3 = ptr2;//error

    weak_ptr ptr3 = ptr;
    //auto ptr4 = ptr3;
    cout << ptr3.use_count() << endl;
    return 0;
}

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

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

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