侯捷 C++ 课程学习笔记:C++ 新标准11/14

server/2025/3/15 4:52:04/

 演进、环境与资源

C++2.0 (C++11/14)新特性

语言(只谈新东西),需要具备,C++ 语法和语意的基础

C++ Standard 之演化

C++ 98(1.0)、C++ 03(TR1,Technical Report 1)、C++ 11(2.0)、C++ 14。

C++ 2.0 新特性包括语言和标准库两个层面,后者以 header files 形式呈现。

C++ 标准库的 header files 不带副档名(.h),如 #include <vector>

新式 C header files 不带副名称 .h,如 #include <cstdio>

旧式 C header files (带有副名称 .h )仍可用,如 #include <stdio.h>

旧式换新式:就是将<stdio.h>改写成<cstdio> 相当于在“stdio”前面加上 c ,后面删除 .h。

仍然可以使用旧式,旧式还是可以完全正常工作的,不过还是适应更换新式

C++ 2.0 新添加的头文件

#iinclude <type_traits>

#iinclude <unordered_set>

#iinclude <forward_list>

#iinclude <array>

#iinclude <tuple>

#iinclude <regex>

#iinclude <thread> 这些都在 using namespace std  

many of TR1 features(特性) that existed(存放) in nameespace 

std::tr1 in the previous release (like shared_pptr and regex) are now part of the standard library under the std namespace.(tr1 特性存放在std::tr1,现在存放在std)

了解使用的编译器对C++ 2.0 的支持度

可以在 Standard C++ 、C++ Rocks! 、谷歌、华为等检索查看。

Dev-C++ 5.11,MinGW with GCC 4.9.2(平台外挂 编译器 GCC)

Dev-C++ 上的ISO C++11 开关(使用Dev-C++)其他平台可能类似有如此开关。

开关位置:点击左上角 “Project”,找到并选择 “Compiler” ,在 “Customize(applies to this project only)”中找到并选择 “Code Generation” 最下面 “Language standard(-std)” 选项中选择 “ISO C++11” (Language standard(-std) 选项中有 ISO C90、ISO C99、ISO C++、ISO C++11、GUN C90、GUN C99、GUN C++、GUN C++11)。

 C++11 FAQ C++ FAQ from Strousstrup

编程时可以查阅的网页

cplusplus.com 、cppreference.com 、GCC, the GNU Compiler Collection- GNU Project (似乎是外网网站)

建议选择使用一款顺手的全文检索工具(帮助我们查看标准库代码)

Test-C++2.0.cpp

第一步,确认支持C++11:macro__cplusplus

Variadic Templates

第一颗震撼弹 Variadic Templates

数量不定的模版参数

... 就是一个所谓的 pack (包) 用于 template paramenters,就是template paramenters pack(模版参数包)

                                                  用于function paramenter  types,就是  function paramenter  types pack(函数参数类型包)

                                                  用于function paramenter ,就是function paramenter pack(函数参数包)

Space in Template Expression、nullptr and stdnull

The requirement to put a space between two closing template expressions has gone。

vector<list<int> >;  // OK in each C++ version

vector<list<int>>;   // OK since C++11

nullptr and std::nullptr_1

C++11 lets you use nullptr instead of 0 or NULL to specify that a spointer refers to no value(which differs from having an undefined value).This new feature especially helps to avoid mistakes that occurred when a null pointer was interpreted as an integral value.For example:

void f(int);

void f(void*);

f(0);               // calls f(int)

f(NULL);        // calls f(int) ifNULL is 0,ambiguous otherwise

f(nullptr);       //calls f(void*)

nullptr is a new keyword.It automatically converts into each pointer type but not to any integral type.It has type std::nullptr_t,defined in <cstddef> (see Section 5.8.1,page161),so you can now evwn overfload operations for the case that a null point is passed.Note that std::nullprt_t counts as a fundamental date type (see Section 5.4.2,page 127).

Automatic Type Deduction with auto

With C++11, you can declare a variable or an object without specifying its specific type by using auto.For example:

auto i =42;//i has type int

double f();

auto d = f();//d has type double

Using auto is especially useful where the type is a pretty long and/or complicater expression.For example:

vector<string> v;

... 

auto pos = v.begin();       //pos has type vector<string>::iterator

注:有不当之处,请批评指正!谢谢~


http://www.ppmy.cn/server/175064.html

相关文章

Qt/C++音视频开发82-系统音量值获取和设置/音量大小/静音

一、前言 在音视频开发中&#xff0c;音量的控制分两块&#xff0c;一个是控制播放器本身的音量&#xff0c;绝大部分场景都是需要控制这个&#xff0c;这个不会影响系统音量的设置。还有一种场景是需要控制系统的音量&#xff0c;因为播放器本身的音量是在系统音量的基础上控…

MySQL中有哪几种锁?

大家好&#xff0c;我是锋哥。今天分享关于【MySQL中有哪几种锁&#xff1f;】面试题。希望对大家有帮助&#xff1b; MySQL中有哪几种锁&#xff1f; 1000道 互联网大厂Java工程师 精选面试题-Java资源分享网 在MySQL中&#xff0c;锁是用来控制并发访问的机制&#xff0c;确…

Prompt工程:大模型沟通指南(人工智能到大模型)

文章目录 人工智能到大模型机器学习深度学习大模型 Prompt工程&#xff1a;大模型沟通的桥梁 在人工智能的广袤领域中&#xff0c;大模型无疑是最为璀璨的明珠之一。它仿佛是一座连接人类与人工智能的桥梁&#xff0c;让我们能够更加深入地探索和利用人工智能的强大能力。而要实…

58.Harmonyos NEXT 图片预览组件架构设计与实现原理

温馨提示&#xff1a;本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦&#xff01; Harmonyos NEXT 图片预览组件架构设计与实现原理 文章目录 Harmonyos NEXT 图片预览组件架构设计与实现原理效果预览一、组件架构概述1. 核心组件层…

ubuntu 在VirtualBox 打不开终端

ctrlaltF3&#xff0c;进入命令行模式sudo nano /etc/default/locale LANG这行的值修改为&#xff1a;en_US.UTF-8执行 locale-gen --purge&#xff0c;等待生成完成reboot重启系统。再次进入系统后&#xff0c;终端就可以正常使用了 参考文章&#xff1a;VirtualBox安装Ubuntu…

蓝桥杯备考:图论初解

1&#xff1a;图的定义 我们学了线性表和树的结构&#xff0c;那什么是图呢&#xff1f; 线性表是一个串一个是一对一的结构 树是一对多的&#xff0c;每个结点可以有多个孩子&#xff0c;但只能有一个父亲 而我们今天学的图&#xff01;就是多对多的结构了 V表示的是图的顶点集…

uni-app中,调用收货地址方法 uni.chooseAddress()不生效的问题

在uni-app中&#xff0c;如果调用收货地址方法 uni.chooseAddress()不生效的话&#xff0c;可以在manifest.json中&#xff0c;打开源码视图&#xff0c;找到mp-weixin&#xff0c;设置 然后将小程序进行重启即可

QT系列教程(13) 事件系统

事件系统 Qt事件系统是非常重要事件传递机制&#xff0c;所有消息传递流程都离不开这个机制&#xff0c;这里主要从重写类的事件响应函数&#xff0c;事件过滤器以及重写event函数三种方式做介绍。 重写事件函数 这种方式最为直接&#xff0c;我们先创建项目,选择QApplicati…