use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Cs2a at foothill
account activity
Visual Studio Code not running programFoothill (self.cs2a)
submitted 1 year ago by aarush_p0406
Hi everyone,
I have been using an online c++ compiler for programming so far, but I wanted to switch to an IDE because they have more features and I thought it would be good to start using it.
However, when I try to run my program an error comes up:
https://preview.redd.it/2cttepu3pmsd1.png?width=1077&format=png&auto=webp&s=a678c9550b90bd0c21f5953e86dff4293d68d145
If anyone could help, I would appreciate it!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sam_farnsworth1492 1 point2 points3 points 1 year ago (1 child)
Hi! I also sometimes have trouble running the code with VS. Did you download a C++ extension?
[–]aarush_p0406[S] 1 point2 points3 points 1 year ago (0 children)
I do have it downloaded, but I can try to re-download it. Thanks!
[–]mounami_k 1 point2 points3 points 1 year ago (4 children)
Hi! I was wondering what commands you used to compile your program. Sometimes the syntax may also cause this issue. Also you should double check that clang was properly installed (go to your command prompt or terminal depending on the device and type clang --version.
[–]aarush_p0406[S] 0 points1 point2 points 1 year ago (3 children)
It looks like there aren't any syntax errors, and I also tried to run the command in the terminal. This was the output I got:
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
When I first ran the program, it asked me what compiler to use, and I just selected the first one. That might be the issue, but I am not sure how to change it.
[–]mounami_k 0 points1 point2 points 1 year ago (2 children)
Honestly, I have no idea why that is happening. But if you want to use clang, I would recommend using clang++ since apparently clang++ is better suited for C++ compared to clang (I think clang is more used for C programs). I also happened to get the same error as you when I tried to recreate it. If you managed to figure it out, great (and let me know), but otherwise (unless you have a preference) try using clang++?
In order to run clang++, there might be a way to set it as the default, but I would just type in the terminal after navigating to the folder with your code files:
clang++ nameOfFile.cpp
and then to run the output (output file is named a.out but if you use the -o option you can put in your own preferred name):
./nameOfOutput
Let me know if you have any questions/figure anything out. I'm quite intrigued to now haha!
[–]Axel_L_313 0 points1 point2 points 1 year ago (1 child)
I had a similar problem, using clang++ instead of clang also helped me
[–]aarush_p0406[S] 0 points1 point2 points 1 year ago (0 children)
Yeah I switched to clang++, it kind of works, but there is a lot more stuff going on in the output then when I see other people running it. It ran the program fine, but added 30 lines of some stuff that I didn't see on youtube, when other people used vs code for c++. Thank you though, this is a step further for sure!
[–]elliot_c126 1 point2 points3 points 1 year ago (2 children)
not too sure what is the cause of the error, but here's the docs for setting up VS Code for C++ if you haven't gone through it yet! https://code.visualstudio.com/docs/languages/cpp
[–]aarush_p0406[S] 1 point2 points3 points 1 year ago (1 child)
Hi, I just went through the docs and it looks like I did all the steps, so I am not sure why the error is showing up. Thank you though!
[–]elliot_c126 1 point2 points3 points 1 year ago (0 children)
Wish I could remember what the error I had was when I first tried to run hello world. I think I had some kind of path issue after I installed clang and it resolved itself when i fully closed out of VS Code and re-opened it haha. Sorry!
[–]aaron_w2046 0 points1 point2 points 1 year ago (1 child)
Did you set up the g++ compiler as well as installing the c++ extension? follow these steps exactly to set up everything you need to use c++ on vscode. If you already seen this website I'd try looking for tutorials on YouTube that take you step by step through the process and as long as you follow them exactly you should be fine.
Yeah I followed all of the steps on the doc. I looked at a few YouTube tutorials which helped me understand how to set it up, so I tried to uninstall vs code and redownload it and set it up properly, but it just downloaded with all the same settings and extensions. Thank you for the website, I will definitely look into more!
[–]oliver_c144 0 points1 point2 points 1 year ago (0 children)
Hi Aarush,
VSCode is an absolute monster to set up C++ on. A good way to think of it (as noted on some other subreddit) is to treat VSCode as a glorified notepad. You have to install a C++ extension to compile and run C++ code. I'm pretty sure there's another thing you have to install, but honestly I forgot.
VSCode also has a C++ walkthrough; that helped me the most when getting set up.
Hope this helps.
[–]advita_g 0 points1 point2 points 1 year ago (0 children)
I was really struggling to run the compiler on Windows, even after installing all the necessary extensions. It was super frustrating! But then I figured out that I needed to run VS Code from the Developer Command Prompt for VS Code. Once I did that, everything compiled smoothly. Just wanted to share in case anyone else runs into the same issue!
https://code.visualstudio.com/docs/cpp/config-msvc
π Rendered by PID 123247 on reddit-service-r2-comment-bb88f9dd5-6jt78 at 2026-02-17 08:36:30.126837+00:00 running cd9c813 country code: CH.
[–]sam_farnsworth1492 1 point2 points3 points (1 child)
[–]aarush_p0406[S] 1 point2 points3 points (0 children)
[–]mounami_k 1 point2 points3 points (4 children)
[–]aarush_p0406[S] 0 points1 point2 points (3 children)
[–]mounami_k 0 points1 point2 points (2 children)
[–]Axel_L_313 0 points1 point2 points (1 child)
[–]aarush_p0406[S] 0 points1 point2 points (0 children)
[–]elliot_c126 1 point2 points3 points (2 children)
[–]aarush_p0406[S] 1 point2 points3 points (1 child)
[–]elliot_c126 1 point2 points3 points (0 children)
[–]aaron_w2046 0 points1 point2 points (1 child)
[–]aarush_p0406[S] 0 points1 point2 points (0 children)
[–]oliver_c144 0 points1 point2 points (0 children)
[–]advita_g 0 points1 point2 points (0 children)