ConfigCat's C++ SDK is now generally available
We're proudly announcing our 16th SDK release! ConfigCat's C++ SDK is now generally available. This SDK is a native C++ implementation of ConfigCat's feature flag management service. It is designed to be lightweight, easy to use, and easy to integrate into your C++ projects.
- Check out the ConfigCat C++ SDK on GitHub.
- Read the ConfigCat C++ SDK Docs and Guides.
About C++
C++ is a cross-platform language that can be used to create high-performance applications. It gives programmers a high level of control over system resources and memory. C++ is used in browser development, operating systems, game engines (ex. Unity, Unreal Engine), graphics applications, embedded, IoT, and many more. We're excited to announce that now we can easily use feature flags in any C++ application, thanks to ConfigCat's brand-new SDK.
How to use the ConfigCat C++ SDK
Prerequisites
- A code editor, for example, Visual Studio. You can download the VS Community Edition from here. -Vcpkg - a package manager that takes charge of your C and C++ dependencies (like the ConfigCat SDK in your project).
How to install vcpkg
git clone https://github.com/microsoft/vcpkg
.\vcpkg\bootstrap-vcpkg.bat
To use it with Visual Studio, we'll need to run the following command (which may require admin approval):
.\vcpkg\vcpkg integrate install
How to use feature flags in a C++ application
TL;DR
- Create a feature flag in ConfigCat.
- Set your project to use the C++ version 17.
- Set Vcpkg as the package manager.
- Add the ConfigCat C++ SDK to your project.
- Instantiate the Configcat Client in your code.
- Call
getValue()
to get your feature flag value
Step 1: Create a feature flag in ConfigCat
Open the ConfigCat Dashboard and add a new feature flag or use an existing one. Note the feature flag's Key
and your SDK Key
(on the top right), as we'll need it later.
Step 2: Set your project to use C++ version 17
In Visual Studio open the project’s property pages and set C++ Language Standard
to at least C++17
.
Step 3: Set Vcpkg as the package manager
On the project’s property pages turn Use Vcpkg Manifest
on. From now on your project's dependencies will be handled by the vcpkg.json
manifest file.
Step 4: Add the ConfigCat C++ SDK to your project
Create the file vcpkg.json
manifest file next to the project’s .vcxproj
file with the following content so that vcpkg will install the ConfigCat C++ SDK at build time.
{
"name": "your-project-name",
"dependencies": ["configcat"]
}
Step 5: Instantiate the Configcat Client in your code
To use the flag we've just created, make sure to include the ConfigCat headers and iostream
to be able to print some text to the console.
#include <configcat/configcat.h>
#include <configcat/consolelogger.h>
#include <iostream>
using namespace std;
using namespace configcat;
Set the log level to INFO for verbose logging to see the feature flag evaluation process.
int main(int /*argc*/, char** /*argv*/) {
// Info level logging helps to inspect the feature flag evaluation process
// Use the default warning level to avoid too detailed logging in your application
configcat::setLogLevel(LOG_LEVEL_INFO);
ConsoleLogger logger;
configcat::setLogger(&logger);
Create the ConfigCat client with your SDK key.
// Initialize the ConfigCatClient with an SDK Key
auto client = ConfigCatClient::get("#YOUR-SDK-KEY#");
Step 6: Call getValue()
to get your feature flag value
bool value = client->getValue("isAwesomeFeatureEnabled", false);
cout << "isAwesomeFeatureEnabled value from ConfigCat: "
<< (value == true ? "true" : "false");
Close the ConfigCat client to release all associated resources on application exit:
ConfigCatClient::closeAll();
return 0;
}
Building and running the app
After running the app, you should see the following output in the console:
isAwesomeFeatureEnabled value from ConfigCat: true
Additional resources
- Sample C++ application that uses the C++ SDK: https://github.com/configcat/cpp-sdk/tree/main/samples
- ConfigCat C++ SDK Docs: https://configcat.com/docs/sdk-reference/cpp/
You worry do not. Your feature flags are served.