There is a much simpler method that doesn't require any setting to build and run C++ code: Put the Code Runner Extension on.
The output will be displayed in the Output Window when the C++ code has been built and executed using the shortcut Ctrl+Alt+N, pressing F1 and then choosing or typing Run Code, or right-clicking the Text Editor and choosing Run Code from the context menu.
Additionally, you might change the configuration under settings .json
The default C++ configuration is as follows when using various C++ compilers: