深入理解 C++ 基础:从代码阅读到整数表达式
1. 阅读 C++ 代码
首先来看一个示例代码:
/// Read the program and determine what the program does.
import <iostream>;
import <limits>;
int main()
{
int min{std::numeric_limits<int>::max()};
int max{std::numeric_limits<int>::min()};
bool any{false};
int x;
while (std::cin >> x)
{
any = true;
if (x < min)
min = x;
if (x > max)
max = x;
}
if (any)
std::cout << "min = " << min << "\nmax = " << max << '\n';
}
这段代码的功能是从标准输入读取整数,记录输入中的最大值和最小值,输入结束后打印这两个值。若输入无数字,则不输出任何内容。
1.1 注释
- 单行注释 :代码第一行以三个连续斜杠
超级会员免费看
订阅专栏 解锁全文
1834

被折叠的 条评论
为什么被折叠?



