Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

2.2 经典的第一个程序

这是经典的第一个程序的一种版本。它在你的屏幕上输出“Hello,World!”:

我们可以将这段文字看作交给计算机执行的一组指令,就像我们交给一个厨师的一张菜谱,或我们用于使一个新玩具工作的一组组装指令。我们来讨论这个程序的每行如何工作,从下面这行开始。

这是实际生成输出内容的一行。它打印字符串Hello,World!,并且紧跟着一个换行;也就是说,在打印出Hello,World!之后,光标将位于下一行的开始位置。光标是一个小的、闪烁的字符或线,它用来显示你可以输入下一个字符的位置。

在C++中,字符串常量是由双引号(")限定的;也就是说,"Hello,World!\n"是一个字符串。\n是一个用于指定换行的“特殊字符”。名称cout是一个标准的输出流。使用输出操作符<<“输入到cout”的字符将显示在屏幕上。名称cout的发音是“see-out”,是“character output stream”的缩写。你在编程时很容易遇到缩写。很自然,在你第一次看到一个缩写还要记住它时会觉得有点儿烦,但是当你开始重复使用一个缩写时,它们将会变得很自然,并且对保持程序文本的简短和可控制是必不可少的。

这行的结尾

是一个注释。在一行中,符号//(符号/称为“斜杠”,这里是双斜杠)之后的任何东西都是注释。注释会被编译器忽略,它是写给那些需要阅读代码的人的。在这里,我们使用注释告诉你该行开始部分实际做了什么事情。 ...

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

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

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

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252