How to add Complier Flags to VSCode

I have tried to add complier flags to my tasks.json, however nothing seems to work. I compile with g++. How can I add them?

To add compiler flags to your tasks.json file in Visual Studio Code for compiling with g++, start by locating or creating the tasks.json file in the .vscode folder of your workspace. Then, open the file and define a build task with the necessary settings. Set the command to g++ and include your desired flags in the args array. For instance, add “-std=c++20” for specifying the C++ standard and other corresponding languages, “-Wall” and “-Wextra” for enabling warnings, “-O2” for optimization, and “-g” for including debugging information. Specify the output file name using “{fileDirname}/{fileBasenameNoExtension}” and the input file as “${file}”. Save the configuration, and press Ctrl+Shift+B (or Cmd+Shift+B on Mac) to run the build task. If it doesn’t work, check the output panel in VS Code for errors and ensure g++ is properly installed and configured in your system’s PATH.