## 译文

C++ is one of the most widely used programming languages in the world. Well-written C++ programs are fast and efficient. The language is more flexible than other languages because you can use it to create a wide range of apps—from fun and exciting games, to high-performance scientific software, to device drivers, embedded programs, and Windows client apps. For more than 20 years, C++ has been used to solve problems like these and many others. What you might not know is that an increasing number of C++ programmers have folded up the dowdy C-style programming of yesterday and have donned modern C++ instead.

C++是世界上应用最广泛的编程语言之一。写得好的C++程序是快速和高效的。该语言比其他语言更灵活，因为您可以使用它创建各种各样的应用程序，从有趣和刺激的游戏，到高性能的科学软件，再到设备驱动程序、嵌入式程序和Windows客户端应用程序。20多年来，C++已经被用来解决这些问题以及许多其他问题。你可能不知道的是，越来越多的C++程序员已经折叠了昨天过时的C风格编程，并使用了现代C++取代

One of the original requirements for C++ was backward compatibility with the C language. Since then, C++ has evolved through several iterations—C with Classes, then the original C++ language specification, and then the many subsequent enhancements. Because of this heritage, C++ is often referred to as a multi-paradigm programming language. In C++, you can do purely procedural C-style programming that involves raw pointers, arrays, null-terminated character strings, custom data structures, and other features that may enable great performance but can also spawn bugs and complexity. Because C-style programming is fraught with perils like these, one of the founding goals for C++ was to make programs both type-safe and easier to write, extend, and maintain. Early on, C++ embraced programming paradigms such as object-oriented programming. Over the years, features have been added to the language, together with highly-tested standard libraries of data structures and algorithms. It's these additions that have made the modern C++ style possible.

Modern C++ emphasizes: * Stack-based scope instead of heap or static global scope. * Auto type inference instead of explicit type names. * Smart pointers instead of raw pointers. * std::string and std::wstring types (see <string>) instead of raw char[] arrays. * C++ Standard Library containers like vector, list, and map instead of raw arrays or custom containers. See <vector>, <list>, and <map>. * C++ Standard Library algorithms instead of manually coded ones. * Exceptions, to report and handle error conditions. * Lock-free inter-thread communication using C++ Standard Library std::atomic<> (see <atomic>) instead of other inter-thread communication mechanisms. * Inline lambda functions instead of small functions implemented separately. * Range-based for loops to write more robust loops that work with arrays, C++ Standard Library containers, and Windows Runtime collections in the form for ( for-range-declaration : expression ). This is part of the Core Language support. For more information, see Range-based for Statement (C++).

• 基于栈的作用域，而不是堆或静态全局作用域
• 自动类型推断而不是显式类型名
• 智能指针而不是原始指针
• std::stringstd::wstring类型（参见<string>）而不是原始char[]数组
• C++标准库容器，如vectorlistmap，而不是原始数组或自定义容器。请参见<vector><list><map>
• C++标准库算法，而不是手工编写的算法
• 通过异常报告和处理错误情况
• 使用C++标准库std::atomic<>进行无锁线程间通信（参见<atomic>）而不是其他线程间通信机制
• 内联lambda函数而不是单独实现的小函数
• 使用基于范围的循环编写更健壮的循环代码，这些循环使用数组、C++标准库容器和Windows运行时集合for ( for-range-declaration : expression )。这是核心语言支持的一部分。有关更多信息，请参见基于范围的语句（C++）

The C++ language itself has also evolved. Compare the following code snippets. This one shows how things used to be in C++:

C++语言本身也有了发展。比较以下代码段。这个例子显示了C++中的事物是如何使用的：

Here's how the same thing is accomplished in modern C++:

In modern C++, you don't have to use new/delete or explicit exception handling because you can use smart pointers instead. When you use the auto type deduction and lambda function, you can write code quicker, tighten it, and understand it better. And a range-based for loop is cleaner, easier to use, and less prone to unintended errors than a C-style for loop. You can use boilerplate together with minimal lines of code to write your app. And you can make that code exception-safe and memory-safe, and have no allocation/deallocation or error codes to deal with.

Modern C++ incorporates two kinds of polymorphism: compile-time, through templates, and run-time, through inheritance and virtualization. You can mix the two kinds of polymorphism to great effect. The C++ Standard Library template shared_ptr uses internal virtual methods to accomplish its apparently effortless type erasure. But don't over-use virtualization for polymorphism when a template is the better choice. Templates can be very powerful.

If you're coming to C++ from another language, especially from a managed language in which most of the types are reference types and very few are value types, know that C++ classes are value types by default. But you can specify them as reference types to enable polymorphic behavior that supports object-oriented programming. A helpful perspective: value types are more about memory and layout control, reference types are more about base classes and virtual functions to support polymorphism. By default, value types are copyable—they each have a copy constructor and a copy assignment operator. When you specify a reference type, make the class non-copyable—disable the copy constructor and copy assignment operator—and use a virtual destructor, which supports the polymorphism. Value types are also about the contents, which, when they are copied, give you two independent values that you can modify separately. But reference types are about identity—what kind of object it is—and for this reason are sometimes referred to as polymorphic types.

C++ is experiencing a renaissance because power is king again. Languages like Java and C# are good when programmer productivity is important, but they show their limitations when power and performance are paramount. For high efficiency and power, especially on devices that have limited hardware, nothing beats modern C++.

C++正在经历复兴，因为能力再次成为国王。像Java和C#这样的语言在程序员的生产力很重要的时候是很好的，但是它们在功率和性能是最重要的时候显示出它们的局限性。对于高效率和功率，特别是在硬件有限的设备上，没有什么比现代C++更出色

Not only the language is modern, the development tools are, too. Visual Studio makes all parts of the development cycle robust and efficient. It includes Application Lifecycle Management (ALM) tools, IDE enhancements like IntelliSense, tool-friendly mechanisms like XAML, and building, debugging, and many other tools.

The articles in this part of the documentation provide high-level guidelines and best practices for the most important features and techniques for writing modern C++ programs.

• C++类型系统
• 统一初始化和委托构造器
• 对象生命周期和资源管理
• 对象拥有资源（RAII）
• 智能指针
• 用于编译时封装的Pimpl
• 容器
• 算法
• 字符串和I/O格式（现代C++）
• 错误和异常处理
• ABI边界的可移植性

For more information, see the Stack Overflow article Which C++ idioms are deprecated in C++11.