Getting started with C++
This tutorial gets you up to speed with C++ development in JetBrains Fleet. It covers the installation, project setup, and working with code.
Install JetBrains Toolbox 1.22.10970 or later: the Download page.
Download and install JetBrains Toolbox.
In JetBrains Toolbox, click Install near the JetBrains Fleet icon.
JetBrains Fleet supports C++ projects with compilation databases.
A compilation database is a JSON file named compile_commands.json, which contains structured data about every compilation unit in the project.
Follow this instruction to generate a compilation database for your project.
tip
Your compile_commands.json can be located anywhere under the project root. Fleet checks all the workspace directories at picks the largest compile_commands.json file.
Press Ctrl0O or select File | Open from the menu.
Select your project root folder and click Open:
The opened directory becomes the root of your workspace:
Smart Mode turns on code insight features for your C++ code.
Click the Smart Mode Status icon in the top-right corner. In the popup that appears, click Enable.
![Smart Mode can't start Smart Mode can't start](https://resources.jetbrains.com/help/img/fleet/1.45/cl_fleet_smartmode_notworking.png)
This message indicates that Fleet might not have been able to download Clangd because of a firewall. Follow the steps below for a workaround.
Download Clangd using the following links:
tip
Correct the version number in the link to get a fresher version when available.
Put the downloaded file into the ~
/.fleet/ directory.Restart Fleet.
Here's what you can do in Smart Mode. The below is not an exhaustive list of Smart Mode features, rather a couple of examples that'll help you to get the feel of how it works in Fleet.
All the errors in your code are highlighted red:
Context-aware completion gives a list of suggestions for names, types, and keywords:
Among the completion suggestions, you can find templates for common code constructs. Select one from the list, and then use Tab to move the caret between stubs:
Available code snippets:
typedef [type] [name];
using [name] [type];
namespace [name] = [namespace];
using namespace [identifier];
using [qualifier]::[name];
using typename [qualifier]::[name];
template<class [name]>
template<typename [name]>
switch ([condition]) { [cases] }
case [expression]:
goto [label];
dynamic_cast<[type]>([expression])
static_cast<[type]>([expression])
reinterpret_cast<[type]>([expression])
const_cast<[type]>([expression])
catch ([declaration]) { [statements] }
concept [name] = [constraint];
#define [macro]([args])
To transform an already typed expression into a different one without moving the caret, add a dot at the end. You will see postfix completion options among the list of suggestions:
For example, you can choose if, and the initial expression will get wrapped into an
if
statement:
Press Ctrl0I to get the list of parameter names in a function call:
Click Show all to view all the usages.
Hover over a class, function, field, or another element to see where and how it is defined:
Select an item to be renamed, press F2, and enter the new name:
Navigate to the declaration of a symbol with Ctrl0B.
Find usages of a symbol with Ctrl0U:
Skim over the errors with Ctrl0E and CtrlShift0E.
Fleet does not provide automation for the process of building a running C/C++ applications.
However, you can use Fleet's language-agnostic run configurations for that. Find below an example for the case of CMake:
{
"configurations": [
{
"type": "command",
"name": "Build",
"program": "cmake",
"args": ["--build", "$PROJECT_DIR$/cmake-build-debug", "--target", "program_name"],
},
{
"type": "command",
"name": "Run",
"program": "$PROJECT_DIR$/cmake-build-debug/program_name",
},
]
}
Thanks for your feedback!