#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <array>
#include <iostream>
#include <memory>
using namespace std;
std::map<int, int> 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:%s\n", f, b);
//istd::map<int, int> DataMap = {{1, 2}, {3, 4}};
//printf("map:%d, %d\n)
for (auto d : DataMap)
{
cout << d.first << endl;
cout << d.second << endl;
}
auto func = [&b](){
b = "aabc";
//cout << b <<endl;
};
func();
cout << b <<endl;
vector<int> 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<string, 4> arr = {"v", "b", "n", "m"};
for (auto tmp : arr)
{
cout << tmp << endl;
}
auto ptr = make_shared<int>(10);
cout << ptr.use_count() << endl;
{
shared_ptr<int> ptr1 = ptr;
cout << ptr1.use_count() << endl;
cout << ptr.use_count() << endl;
}
cout << ptr.use_count() << endl;
unique_ptr<int> ptr2(new int(10));
//auto ptr3 = ptr2;//error
weak_ptr<int> ptr3 = ptr;
//auto ptr4 = ptr3;
cout << ptr3.use_count() << endl;
return 0;
}
C++11简单练习
最新推荐文章于 2022-05-23 10:53:17 发布