C++11——1.小练手
来源:互联网 发布:网络机顶盒看电视直播 编辑:程序博客网 时间:2024/05/02 01:01
#include <iostream>#include <vector>#include <map>#include <string>#include <algorithm>#include <tuple>using namespace std;// nullptrvoid F(int a) {cout << "F(int a):" << a << endl;}void F(int *p) {cout << "F(int *p):" << p << endl;}void main() {// autocout << "auto---------------------\n";{auto a = "test auto\n";cout << a;vector<int>v;v.push_back(0);v.push_back(1);v.push_back(2);for (auto itr = v.begin(); itr != v.end(); ++itr) {cout << *itr << endl;}// template <class Product, class Creator>// void processProduct(const Creator &creator) {// Product *val = creator.makeObject();// }// // template <class Creator>// void processProduct(const Creator &creator) {// auto val = creator.makeObject();// }}// decltypecout << "decltype---------------------\n";{int x = 3;decltype(x) y = 3;// template <class Creator>// auto processProduct(const Creator &creator) -> decltype(creator.makeObject()) {// auto val = creator.makeObject();// }}// nullptrcout << "nullptr---------------------\n";{int *p = nullptr;int *q = NULL;cout << "p equals q: " << (p == q) << endl;//int a = nullptr;// errorF(0);F(nullptr);}// forcout << "for---------------------\n";{//map<string, int> m {{"a", 1}, {"b", 2}, {"c", 3}};map<string, int> m; m["a"] = 1; m["b"] = 2; m["c"] = 3;for (auto p : m) {cout << p.first << ":" << p.second << endl;}}// lambda// [Func Object Param](Func Param)->ReturnType {Func Body}cout << "lambda---------------------\n";{//vector<int> v {5, 4, 3, 2, 1};vector<int> v; v.push_back(5); v.push_back(4); v.push_back(3); v.push_back(2); v.push_back(1);int a = 2, b = 1;// can visit global var 'b'for_each(v.begin(), v.end(), [b](int &x){ cout << (x + b) << endl;});// [=] means can visit all outer var (by value)for_each(v.begin(), v.end(), [=](int &x){ x *= (a + b);});for_each(v.begin(), v.end(), [=](int &x)->int{ return x * (a + b);});}// var params length templatecout << "var param len template---------------------\n";{auto t1 = make_tuple(1, 2.0, "c++ 11");//auto t2 = make_tuple(1, 2.0, "c++ 11", {1, 0, 2});// template <typename head, typename... tail>// void Print(Head head, typename... tail) {// cout << head << endl;// Print(tail...);// }}// init methodcout << "init method---------------------\n";{int arr[3] = {1, 2, 3};vector<int> v(arr, arr + 3);// int arr1[3] {1, 2, 3};// vector<int> v1 {1, 2, 3};// map<int, string> {{1, "a"}, {2, "b"}};// string str{"Hello World"};}getchar();}
0 0
- C++11——1.小练手
- 小程序练手(c++)
- Android 小项目练手——扫雷
- c语言练手——记录1
- 【练手小程序——01】迷宫问题
- 【练手小程序——02】STL容器实现
- 练手小项目(1)——智能聊天机器人
- 练手小项目(4)安全卫士——黑名单拦截
- 练手小项目(5)安全卫士——手机加速
- Java练手小程序——QQ聊天
- 小练手
- c++11 文本查询练手小程序
- 贪吃蛇 Linux C语言 第二次小练手
- C练手程序--1.位操作
- CB程序练手总结——家用记账小程序(附链接)
- 练手小项目(4)安全卫士——黑名单拦截 利用内容提供者删除通话记录
- 安卓开发小练手之手机卫士开发(1)——Splash界面
- 安卓开发小练手之手机卫士开发(2)——主界面
- IO流(写入转换流)
- 脚本的一点小错误 也可能使游戏变得巨卡
- IO流(改变标准输入输出设备)
- OverScroll用法
- hive中对复杂数据类型的支持
- C++11——1.小练手
- 扩展vbox的虚拟磁盘(.vdi)
- nyoj-1027-阵地防守
- android源码下载mac
- poj 1112 Team Them Up!(建图+dp)
- IO流(流操作规律-1)-(流操作规律-2)
- java 虚拟机类加载机制
- 我的伤 你不懂
- iOS_14_tableViewController_xib创建和封装自定义cell