Skip to Content
C++语言导学(原书第2版)
book

C++语言导学(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
5h 35m
Chinese
Pearson
Content preview from C++语言导学(原书第2版)

9.5 建议

[1] 使用std::string来获得字符序列;9.2节;[CG:SL.str.1]。

[2] 优先选择string操作而不是C风格字符串函数;9.1节。

[3] 使用string声明变量和成员,但不要将它作为基类;9.2节。

[4] 返回string应采用传值方式(依赖移动语义);9.2节、9.2.1节。

[5] 直接或间接使用substr()读取子字符串,使用replace()写入子字符串;9.2节。

[6] 如需要,我们可以扩展或收缩一个string;9.2节。

[7] 当需要范围检查时,应使用at()而不是迭代器或[];9.2节。

[8] 当需要优化速度时,应使用迭代器或[]而不是at();9.2节。

[9] string输入不会溢出;9.2节、10.3节。

[10] 只有迫不得已时,才使用c_str()获得一个string的C风格字符串表示;9.2节。

[11] 使用stringstream或通用的值提取函数(如to<X>)将字符串转换为数值;10.8节。

[12] 可用basic_string构造任意类型字符的字符串;9.2.1节。

[13] 对字符串字面值使用后缀s来指明是标准库string类型;9.3节;[CG:SL.str.12]。

[14] 如果函数需要读取以不同方式保存的字符序列,使用string_view作为其实参;9.3节;[CG:SL.str.2]。

[15] 如果函数需要写入以不同方式保存的字符序列,使用gsl::string_span作为其实参;9.3节;[CG:SL.str.2][CG:SL.str.11]。

[16] 将string_view看作一种附带大小的指针,它并不拥有字符;9.3节。

[17] 对字符串字面值使用后缀sv来指明是标准库string_view类型;9.3节。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787111633280