C++ 错误处理、循环结构与格式化输出详解
1. C++ 常见错误分析
在 C++ 编程中,我们经常会遇到编译器给出的各种错误信息。有些错误信息很有帮助,能让我们迅速定位问题;而有些则晦涩难懂。下面通过一个包含故意错误的代码示例,来分析常见的错误类型。
// Listing 6-1. Deliberate Errors
1 #include <iosteam>
2 // Look for errors
3 int main()
4 [
5 std::cout < "This program prints a table of squares.\n";
6 "Enter the starting value for the table: ";
7 int start{0};
8 std::cin >> start;
9 std::cout << "Enter the ending value for the table: ";
10 int end(start);
11 std::cin << endl
12 std::cout << "# #^2\n";
13 int x{start};
14 end = end + 1; // exit loop when x reaches end
15 while (x != end)
16 {
17 std:cout << x << " " << x*x << "\n";
18 x = x + 1;
19 }
20 }
超级会员免费看
订阅专栏 解锁全文
11万+

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



