I am very new to C++ and I've wanted to learn it. I have installed gdb v. 12.1, g++ v. 12.1.0 and gcc 12.1.0 using Msys2 as the tutorials I have followed have told me to. Additionally I have copied this line of code to print out "Hello world!" from the tutorial.
This is the code:
#include <iostream>
using namespace std;
int main(){
cout << "Hello world!" << endl;
return 0;
}
But the problem is that if I run the code I get an error saying "Syntax error" with an arrow pointing towards the "using namespace std;" line.
Apparently Visual Studio Code has tried to execute the code as Python. The code runs when I press the debug button top right of the screen. But when I press the F5 key, then it tries to run Python instead. How can I make it so when I press F5 then it compiles and runs my file as C++?
I have installed the C/C++ extension and I have a launch.json file as well.
Tasks.json file:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
]
}
