0

I am new to C++, having just a bit of programming experience in Python. On setting C++ up in VSCode, I have installed C/C++ by Microsoft, C/C++ Extension Pack and also Code Runner by Jun Han. These choices, especially the latter, were made based on some Youtube videos I watched.

Upon trying to Initialize with the curly brackets, I realised the code wouldn't compile. I ran a check compiler program and found out the compiler's version is C++98. I want to change to a more recent version which supports the newer features.

That said, how exactly do I change a compiler version, and which one do you recommend? Is C++11 already outdated?

I tried looking it up, and I think the line code-runner.executorMap could be useful, but I don't really know how to use it. Is there a way to do it in Settings or will I have to change it through the Terminal?

Thanks in advance!

imarqs
  • 1
  • 2
  • My advice is to uninstall MinGW start over and follow the official VSCode instructions on how to setup MinGW using msys2: [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw) That compiler will be gcc-12.2 and default in c++17 I believe. – drescherjm Jan 28 '23 at 23:23
  • What platform are you running vscode on? Which compiler have you installed? I don't recommend using code runner, it'll soon start getting in your way if you do anything more complicated than using a single file. Use a proper c++ build system like cmake (which has a vscode plugin that makes using c++ much easier) – Alan Birtles Jan 29 '23 at 03:16

1 Answers1

2

I will try to help you step by step :

  1. Uninstall MinGW from your pc
  2. Install MSYS2 from here (Window 8.1 or newer)
  3. Check the option : "Run MSYS2 now" and open the shell
  4. Digit : pacman -Syu to update packets
  5. Open the pink app : MSYS2 MSYS by browsing it from the search bar of Windows
  6. Digit pacman -Su to update it too
  7. Exit and now open the blue app called : MSYS2 MinGW 64-bit
  8. In the shell in ordere to install the compiler digit : pacman -S mingw-w64-x86_64-gcc
    (64 Bit System) pacman -S mingw-w64-i686-gcc (32 Bit System)
  9. Now for the debugger : (64 bit) pacman -S mingw-w64-x86_64-gdb (32 bit) pacman -S mingw-w64-i686-gdb
  10. From the command prompt of Windows digit these 3 commands to check that everything was installed correctly :

gcc --version

g++ --version

gdb --version

  1. Go to this website and go to the step number 6 to configure the Path of mingw (if you installed 64-bit) :
  2. Now because you have already installed C/C++ extension , create a new folder containing your source file, (VERY IMPORTANT because a file won't compile if it's not into a folder ! ) and from the "Terminal" section of VScode select : "Configure Default Build Task" while selecting a c++ file and click : "C/C++ : gcc.exe build active file"
  3. A folder called .vscode will show up containing the file : tasks.json, that is used for telling the compiler all the parameters in order to compile your code.
  4. I recommend to use Powershell as default terminal if you want to set it then press CTRL + SHIFT + P and search for "Terminal: Select Default Profile" and select powershell.
  5. From the "Run" section select "Run Without Debugging" Or "Start debugging" and you are good to go ! Just check the terminal in the bottom section of vscode for the output of your code ! Hope it helps!
Lvcaa
  • 61
  • 7
  • Your 64/32 bit labels are inconsistent (with regard to where they appear in relation to the package name), and after updating your PATH in Windows you need to reboot. I wouldn't recommend repeating official documentation here, unless you intend to maintain this answer if/when the official documentation makes changes. Better to just refer OP to the source. – sweenish Jan 29 '23 at 01:21
  • I don't see anything in the question to suggest tuyere using mingw or even Windows? – Alan Birtles Jan 29 '23 at 03:17
  • @sweenish I know that 64/32 Bit instructions are not very clear but I just wanted to show that there is not a single command for everyone, and I was supposing that he has a 64-Bit machine, plus you are right when you say that It would have been better to just refer to the official documentation but sometimes I find them hard to understand and I preferred to help as much as I can. Ty for the comment – Lvcaa Jan 29 '23 at 08:14
  • @AlanBirtles what do you mean by that? – Lvcaa Jan 29 '23 at 08:14
  • Lvcaa and @AlanBirtles, thank you for the contributions! I have a Macbook, I forgot to mention it. Would the instructions be similar? – imarqs Jan 29 '23 at 08:28
  • @imarqs you have to follow this procedure [here](https://code.visualstudio.com/docs/cpp/config-clang-mac), the compiler will be Clang instead of gcc and gdb, I think that this documentation is far more simple than the windows one so I hope you manage to configure everything correctly, I can't help you that much because I never touched MacOS and I've always used Windows as my OS. – Lvcaa Jan 29 '23 at 09:01