I am learning c++ and it occurred to me to simulate the print
python function with the following code
using namespace std;
template <class... Args>
void print(Args... args){
((cout << args << ' '), ...);
cout << endl;
}
This works for me, however a warning appears in the console
functions/functionsPy.cpp:10:26: warning: fold-expressions only available with -std=c++1z or -std=gnu++1z
((cout << args << ' '), ...);
^~~
Apparently it tells me that this syntax is available from a certain version. So how can I specify the compiler version when executing it in vscode?
For now I use the extension Code Runner
to execute the code, but I don't know if it will be the right one in this case.
To be able to execute the code it is recommended that you install the
C/C++
Microsoft extension, this extension already provides a way to compile the code. This compilation is carried out by means of a command found in a configuration file. The vscode guide provided when you start in C or C++ gives you the steps to create this configuration file, which I will also tell you about here.The way to specify the argument would be in the form
C:\MinGW\bin\g++.exe -g "ruta\de\archivo\archivo.cpp" -std=c++17
but since you use an extension this work is automated by it, so we will see the steps to configure the extension correctly.First we need to create a folder called
.vscode
where the configuration files will go. Then a file called should be createdtask.json
in which some build commands will go. Most likely you already have this folder and this file, so just adjust or add what you need.The structure should be more or less like this:
Remember that you must place the path where you have your executable.
What you must change is the part of
args
entasks
, where you must add another argument indicating the version of the compiler you want to use, thus:With this, everything would be done, now you can compile your file using the version
c++17
using the default extensionC/C++
.In the case of
Code Runner
the process would be the same, we only go to the configuration of the extension, which will also be a.json
. Be careful here, since the extension has different configurations, where you can make a general configuration, of the workspace or of a project in which you work, make the modification in the scope that you think is necessary.Once located in the file you must locate the section
code-runner.executorMap
, if it does not exist you can create it but let the autocomplete generate it, since this section includes all the commands for the compilation and execution of different files in different languages.After you have located or created the above, now look for the extension
cpp
, for example here it is afterc
:You will need to edit the build command by adding the argument that specifies the compiler version, for example:
With this it would already be configured
Code Runner
to be able to use the versionc++17
when compiling your code :D.