Creating a Simple C++ Application to Use Modern C++ Features

From RAD Studio
Jump to: navigation, search

Go Up to Modern C++


C++Builder provides support for C++11, the most recent version of the C++ standard.

The simplest way to test and use the new C++11 features in C++Builder applications is to create a C++ console application, as described in the following steps. You can also use C++11 features in any C++ 64-bit Windows application created with RAD Studio, such as a C++ VCL forms application or a C++ multi-device application. Using a C++ console application gives you a simple application in which you can test the C++11 syntax without a framework attached.

Note: The same basic steps described here (creating a C++ console application) are useful for practicing any features of the C++ compiler, or for doing "bare bones" C++ development and testing, with only the RTL attached.

Steps

  1. Choose File > New > Other.
    FileNewOther.png

  2. The New Items dialog box appears. Click C++Builder Projects, select Console Application, and click OK.
    C++NewCOnsoleApplication.png

  3. The New Console Application (C++) dialog box appears. Make sure that C++ is selected as source type. If you want to select a framework for your application, choose either VCL or FireMonkey on the Target Framework combo box; if not, choose None. Leave the other options to default and click OK.
    NCA01.png

  4. In the Projects Window, right-click Target Platforms and select Add Platform.
    AddPlatfromRC.png

  5. In the Select Platform dialog box, select 64-bit Windows and click OK.
    SelectPlatform64.png

  6. The Code Editor appears, displaying skeleton code for a simple C++ application. You can write your C++11 code inside this file.
    For example, the following piece of code uses the auto keyword as defined in C++11:
#include <iostream>
int main() {
        char array[] = {'C', '+', '+', '1', '1'};
        for (auto&i : array) {
                printf("%c", i);
        }
        std::cin.get();
        return 0;
}
7. Press the F9 key or select Run > Run to run the application:
RunApplication.png

For C++11 code examples, see Modern C++.

See Also