I had this issue recently and what fixed it was selecting g++ as my compiler rather than gcc The difference between gcc and g++ is that gcc was made for c programs but can run c++ programs while g++ was specifically made to run c++ programs. To access the dropdown that would allow you switch compilers you’d have to delete the .vscode folder and then run your c++ file.
