HomeОбразованиеRelated VideosMore From: ProgrammingKnowledge

Set Up C++ Development With Visual Studio Code on Windows 10 (VS Code)

1610 ratings | 136664 views
In this video I am going to show, How to Set Up C++ Development With Visual Studio Code on Windows 10. We will use MinGW with VS code as our compiler and debugging tool. So First I will show How to install mingw. The we will see how to create, build and compile our first C++ Program on VScode. With an updated VS Code you can do it in the following manner: Hit (Ctrl+P) and type: ext install cpptools Open a folder (Ctrl+K & Ctrl+O) and create a new file inside the folder with the extension .cpp (ex: main.cpp): Type in your code and hit save. Press (Ctrl+Shift+P and type, Configure task runner and then select other at the bottom of the list. { "version": "2.0.0", "tasks": [ { "label": "build hello world", "type": "shell", "command": "g++", "args": [ "-g", "helloworld.cpp" ], "group": { "kind": "build", "isDefault": true } } ] } Hit (Ctrl+Shift+B to run Build task. This will create the .obj and .exe files for the project. For debugging the project, Hit F5 and select C++(Windows). In launch.json file, edit the following line and save the file: Below is an example using the MinGW GDB debugger: { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:\\mingw\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build hello world" } ] } Hit F5. -------------------Online Courses to learn---------------------------- Blockchain Course - http://bit.ly/2Mmzcv0 Big Data Hadoop Course - http://bit.ly/2MV97PL Java - https://bit.ly/2H6wqXk C++ - https://bit.ly/2q8VWl1 AngularJS - https://bit.ly/2qebsLu Python - https://bit.ly/2Eq0VSt C- https://bit.ly/2HfZ6L8 Android - https://bit.ly/2qaRSAS Linux - https://bit.ly/2IwOuqz AWS Certified Solutions Architect - https://bit.ly/2JrGoAF Modern React with Redux - https://bit.ly/2H6wDtA MySQL - https://bit.ly/2qcF63Z ----------------------Follow--------------------------------------------- My Website - http://www.codebind.com My Blog - https://goo.gl/Nd2pFn My Facebook Page - https://goo.gl/eLp2cQ Google+ - https://goo.gl/lvC5FX Twitter - https://twitter.com/ProgrammingKnow Pinterest - https://goo.gl/kCInUp Text Case Converter - https://goo.gl/pVpcwL -------------------------Stuff I use to make videos ------------------- Stuff I use to make videos Windows notebook – http://amzn.to/2zcXPyF Apple MacBook Pro – http://amzn.to/2BTJBZ7 Ubuntu notebook - https://amzn.to/2GE4giY Desktop - http://amzn.to/2zct252 Microphone – http://amzn.to/2zcYbW1 notebook mouse – http://amzn.to/2BVs4Q3 ------------------Facebook Links ---------------------------------------- http://fb.me/ProgrammingKnowledgeLearning/ http://fb.me/AndroidTutorialsForBeginners http://fb.me/Programmingknowledge http://fb.me/CppProgrammingLanguage http://fb.me/JavaTutorialsAndCode http://fb.me/SQLiteTutorial http://fb.me/UbuntuLinuxTutorials http://fb.me/EasyOnlineConverter





Html code for embedding videos on your blog
Text Comments (252)
Ghion Kebede (2 days ago)
sounds like porn video at 0:00
Parth Udawant (8 days ago)
The download package keeps on failing to download!
cz48b1 (8 days ago)
Outstanding!!! Thanks for sharing.
The xD (9 days ago)
is this acceptable for windows 7 ??
武腾飞 (10 days ago)
Very helpful. Thank you very much
Sohail Pathan (11 days ago)
how to run new program ? when we debug new program it shows main.cpp output
Ravgeet Dhillon (11 days ago)
A big big thanks for this valuable tutorial.
In c_cpp_properties.json, I don't see a "browse" or a "path" in it
+Manish Pritwani , Nope I just went for Atom. Best of luck with yours.
Manish Pritwani (10 days ago)
Vishaal karthik Muralidharan hey bro did you got the solution... I m also stuck here so if you found the solution kindly suggest
JeongHyun SEO (18 days ago)
When it comes to debugging mode, this video didn't work for me . After setup, I met an error message "gdb failed with message not in executable format (+ alpha) " So I deleted mingw and downloaded mingw 64 from (https://sourceforge.net/projects/mingw-w64/). It worked for me.
Farooq Malik (19 days ago)
Why it is so complicated? Just installed Visual Studio and off you go. No need to install compiler and ridiculously complicated procedure. Just wasted my 15 minutes watching this video.
hunyb ers (20 days ago)
Poor IDE.
kodaloid (21 days ago)
Should be noted you are using a version of MinGW that ened development in 2013, you should be using Mingw-w64 that restarted the project in 2015, look at http://mingw-w64.org/doku.php Excellent tutorial though, worked a treat for me even with the new version of mingw :)
Blue Blue (23 days ago)
Can you share about the way to configure c_cpp_properties.json, tasks.json and launch.json for adding static library, dll in VS Code's C++ project? Especially adding the C++ boost library in VS code. Thanks for your interesting videos.
hello World (24 days ago)
thanks alot
Mansi Sharma (26 days ago)
it's not working in my system ......
Dvir Arazi (27 days ago)
Can someone please explain to me WHY such a tedious process is required to do such a simple thing? What is the proper way to learn these things? Do the creators expect people to look up YouTube videos to figure out this stuff? How do I do stuff such as including SFML and the like? How am I expected to learn how to do such a thing? What if I don't find a tutorial? Can someone please explain that?
thenegative hunter (30 days ago)
>> vorsion <<
XCV_DRYMMO (1 month ago)
visual studio code for when debbuging and analysing a component not boaring it is the best but code writing nope very slow . but tutorial is for novice it is a great lecture thanks a lots .
Bilal Ahmad (1 month ago)
Great. It Worked xD
Your Name (1 month ago)
thank you so much
Tyler Welch (1 month ago)
Thank you so much! This was extremely helpful!
John Caballero (1 month ago)
i am currently using MinGW to my sublime... but i want to use this MinGW to VisualStudio too... is it safe to follow this steps?
Hitarthi Shah (1 month ago)
much helpful !
Uros Krstic (1 month ago)
Really helpful tutorial, saved me a lot of time and effort, thanks.
Peter Girnus (1 month ago)
Thanks! Great Tut.
Shahd Seddik (1 month ago)
Thank you very much for the helpful tutorial! I am wondering, do I have to repeat the same process for every single C++ program I wish to write?
Shivam Wagh (1 month ago)
following ^
Ihtesham Qazi (1 month ago)
These configurations worked for both c and cpp files without any intellisense and path errors. This may help someone stuck with the green squiggly lines on iostream.h. Thanks { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "C:\\MinGW\\include", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/tr1", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32", "C:/MinGW/lib/gcc/mingw32/6.3.0/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.15.26726/bin/Hostx64/x64/cl.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "msvc-x64", "browse": { "path": [ "${workspaceRoot}", "C:\\MinGW\\include", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/tr1", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++", "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32" ] } } ], "version": 4 }
Sai Saketh (1 month ago)
Thanks,really helped :)
Shreevatsa Bhat (1 month ago)
in tasks.jasn whn i tried to build it is showing not recognized....plz give me d sol!!!
George Hatoutsidis (1 month ago)
Thank you. one more step accomplished.
REBEL (1 month ago)
what to do for c??
Chí Hiếu Vũ (1 month ago)
what if i want to run more .cpp files instead of having only one file main.cpp? Please help :(
anas khan (1 month ago)
do we have to it everytime??? what to do just we write few lines of code and then compile it by using this tricky process?
RealityXHD (1 month ago)
Thanks a lot for this video! It really helped me a lot. I was getting some errors about g++ in vscode. I think adding the mingw path to the system's variable directory really solved the whole problem. I tried running the file again without going through the rest of the steps in the tutorial and it still work!!! Once again, thank you very much!
KazzArie (1 month ago)
whoa. microsoft really could have made all this easier on us n00bz
Yashasvi Bajpai (1 month ago)
best!!!!
Mladen Milosavljevic (2 months ago)
why do you use the other compiler?
Wilber EH (2 months ago)
Que se necesita para trabajar en windows
댕댕이 (2 months ago)
curse you microsoft tutorial, what a fraud
Hưng Bê (2 months ago)
thank you so much :3 this is heplful
PugmaPug (2 months ago)
oh. I hoped with VS code I could use any programming language easily as a beginner. Will use VS then
Aakif Sultan (2 months ago)
Wonderful. Detailed and easy to follow.
C0d3r Cr33d (2 months ago)
Great Tutorial! One question: When i hit shift+b the compiler can't find my file. Do i have to enter the full path of my workspace instead of just enter "main.cpp" in the task.json?
Music Blog (2 months ago)
error. /bin/bash: g++: command not found The terminal process terminated with exit code: 127 How to fix?? bro
Sarwar Hayatt (2 months ago)
Will C also run on this?
Vasudev Gaonkar (2 months ago)
Hey! Sir... I'm unable get c/c++ extensions... What should I do now?
At start it is written: Choose the programming language: C++ (Windows) C++ (GDB/LLDB) Note.js I choose both c++, but nothing happens, upon restart, again this happens. I don't know, what can I do. Plz help. #include <iostream> using namespace std; int main() { cout << "Why it's isn't work?" << endl; return 0; system ("pause") }
Z.P. Su (2 months ago)
thanks for your video
Cosmic DooHickey (2 months ago)
This is fucking annoying. How can we get a general way of compiling and debugging for novices? Why must there be such a complicating way of compiling and debugging a single program.
TANMOY BANERJEE (2 months ago)
i just cant describe in words how much your videos help me.....
Ashwin Nanda (2 months ago)
And also why that green error doesnot go from include command and red colour in the file name?
Ashwin Nanda (2 months ago)
Do we need to follow all these steps for every new cpp file we create? I mean always edit cpp _settings.json and task.json for every new cpp file?
Blue Blue (23 days ago)
No, cpp_properties.json and task.json is used to build project, but not which file. If you need to debug, you need to configure the launch.json file.
George Hatoutsidis (1 month ago)
copy and paste bro, that is constant time.
Panama Jack (2 months ago)
settings? no. Settings can be workspace or user local, so if they are common settings, you put them in the user settings file, and if they are workspace specific, put them in the workspace's settings file. tasks.json is workspace local. It's like a makefile. The editor and some extensions can autogenerate boilerplate tasks files, or try to guess at what you want tasks to do, but there are a million ways to compile a collection of c/c++ source files, and you aren't necessarily only compiling one sort of file in a workspace. So developer input is almost always necessary.
Razvy Razvan (2 months ago)
Good tutorial but dear god all the troubles you have to go through. I would rather use Visual Studio and just press one button.
Panama Jack (2 months ago)
It makes more sense if you are used to using non-microsoft c compilers. this setup procedure is roughly the same on windows, linux, and mac if you are using a c compiler that uses standard options parsing. You can even create a tasks.json file in a way that has operating system specific directives so that the one tasks.json file will work everywhere you need it to. You generally do not of this flexibility with visual studio project files.
Vishal Mhasawade (2 months ago)
Very detailed procedure! just a quick question, is this a generic process?i.e. if i create any file named main.cpp will this process let me do build and debug or do i have to make some changes to json files?
SravanKumar Veerapu (2 months ago)
thanks
Fockker (2 months ago)
Im getting this error: 'g++' is not recognized as an internal or external command, operable program or batch file. Ive followed everysingle step carefully, someone help please.
Naksha B (2 months ago)
My command prompt is showing the error as 'g++ is not recognized as an internal or external command, operable program or batch file' even though I have added the correct path to system variables.... Please help
Panama Jack (2 months ago)
have you restarted the command prompt? Environment variables are immutable. Outside programs cannot change how a program sees them. The program has to be restarted to see the changes. In some cases, depending on how they were set, you might have to logout and back into your account session to see the changes.
Fockker (2 months ago)
same over here
TheLivelyHacks (3 months ago)
How to give custom build name instead of a.exe?
TheLivelyHacks (3 months ago)
How to give custom build name instead of a.exe?
Akmal Azar (3 months ago)
When we doing this for c language what are the changes need to be done sir?
Jérémy Lamy (3 months ago)
This video is EXTREMELY useful! I have spent hours to compile C with VS Code. The documention is complete trash. This guy is the only one to explain everything. Thank you very much!
Yash Bhatia (3 months ago)
hello green line is not coming under #include<iostream> i have not given a path my output section is same as yours before giving path
I understand that the author put a LOT of effort into carefully preparing this lesson and recording this video... ... but starting around 10:00 the video becomes unreliable (the author CLEARLY instructs viewers to "edit the IncludePath variable... then promptly proceeds to edit a DIFFERENT variable, all with COMPLETE CONFIDENCE that "all is well" :-?... Then at 13:02 a "settings.json" file MYSTERIOUSLY appears with NO explanation ? I find it hard to believe there are comments below that this all worked PERFECTLY for some people - how is that possible ??? HOW did YOU all create the missing settings.json file ??? There ARE very useful lessons to be gotten from this video; but there are also incredibly ANNOYING points-of-confusion that left me baffled and frustrated. HOW to make a settings.json file if my own project DIDN'T magically/mysteriously create one ??? CURRENTLY when I try to run the Build Task (ctrl-shift-b), I get a "g++.exe; file or directory not found" error HERE's the error: > Executing task: g++ g main.cpp < g++.exe: error: g: No such file or directory UPDATE 1 HOUR LATER, WHERE CODE IS NOW WORKING (and Mark has to eat a little crow)... ============================================================================ 1. MY test app DIDN'T auto-generate the settings.json file; but it turns out it ISN'T (apparently) required for the code to work :-) 2. I was getting the above error because I'd added "g" instead of "-g" in my args block of my tasks.json document !!! 3. I STILL find it ANNOYING and CONFUSING that all the settings & references sloppily "interchange" references to BOTH "gcc.exe" AND "g++" in all the settings. 4. My test app IS working now, so it IS possible. APOLOGIES TO THE AUTHOR FOR DOUBTING HIS TEST APP WORKED :-) -Mark in North Aurora IL
László Danilovic (3 months ago)
This is ridiculous, does it really take that MUCH just to write programs in c++?? I can't believe that in 40 years they couldn't come up with a solution for any IDE so coding with C++ can be learned. But a big thanks to this Channel's Owner that he's sharing this information.
vs code is for geeks, and geeks likes micro-configuration like configuring VS Code
PhoenixRisingLoL (1 month ago)
sai surya madhav  its a code editor. An out-of-the-box IDE would be QT or Visual Studio :)
Walid Jabari (1 month ago)
uh, code::blocks ?
sai surya madhav (2 months ago)
+László Danilovic thanx man....I thought visual studio code is the IDE and spent soooooo much time figuring out how to run a simple code
László Danilovic (2 months ago)
Cool, thanks a lot! :)
Blue Silhouette (3 months ago)
i created the cpp file inside a folder , after build and running the file it created an .exe file but outside the folder !!! How to make it that my .exe file has the same folder location with my .cpp file???
Raul Escobar Ortiz (3 months ago)
hi ppl only to clarify, thx for the video and this works 100% follow the step a it say I waste like 3 days trying to do all this guy mayde in 30 minutes and finally can work with c++ in visual studio code n.n
Sakib Hassan (3 months ago)
Awesome!!
Jonas Karg (3 months ago)
MINGW does not support strings.. Whenever i instantiate a string and run the compiled program it instantly closes. That's a major downside.
Panama Jack (2 months ago)
this sounds like MINGW does support strings (otherwise the program wouldn't even compile) but some other compiler specific difference (or just something you are overlooking) is causing a segfault.
Mark Wilbur (3 months ago)
Why mingw instead of the MS optimizing compiler?
Cloete Delport (3 months ago)
This helped a lot.Thanks !!!
vgfhhjko (3 months ago)
I had to re-boot to update Path, then it worked.
abhay kothari (3 months ago)
Superbly and clearly presented with all details !
Giovanni Carmona (3 months ago)
Can you do an update video for version 4? Everything is different once you get to 10:00 on this video. Thanks!
Asad Nawaz (3 months ago)
Need help: c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status Not understanding how to fix this? :/
Ruben Sargsyan (3 months ago)
I can't open a.exe. What to do ?
Ruben Sargsyan (3 months ago)
G++ is not recognize. What to do, how to solve this problem
Aayush Chopra (3 months ago)
Unable to start debugging. Program path "....." is missing or invalid. GDB failed with message "..directory": not in executable format: File format not recognised. Can anyone help me with this?
himanshu chourasia (1 month ago)
The GDB you are using of 32 bit Try using 64 bit one use cygwin
herr ste (4 months ago)
Super video man, have been looking for this for some time, thank you
Ewen Goisot (4 months ago)
11:57 here is why I don't want to usee Windows any more…
Xian Chen (4 months ago)
I can't run a.exe it shows an error for some reason..
SHRUTIKA SONAWANE (4 months ago)
Sir i cant understand that how do you run the program to activate mingw will you please send me via description
Mike J (4 months ago)
This sht is annoying af, nty
Cid Monza (4 months ago)
as a beginner I found this way complicated... I think I preffer the normal VS
BrewNCode (4 months ago)
I have the exe file but I can't run it
Black Spider (4 months ago)
Thank you "Sir".
ancient child (4 months ago)
thanks man you saved my life!! <3
lolomap (4 months ago)
What is this accent? It's awesome!
Magical Blitz (4 months ago)
Is there a difference between MinGW and C/C++ by Microsoft?
Magical Blitz (4 months ago)
Never mind I take that questions back.
serpathius (4 months ago)
I didn't get a green squiggly line and in the output I get \.vscode\extensions\ms-vscode.cpptools-0.17.5\bin\Microsoft.VSCode.CPP.Extension.exe failed.
Serge Lussier (4 months ago)
Do you realize that you made a very big mistake at the includepath settings? ( I stopped to watch there, but I am sure you have fixed your newbie class mistake later because vscode would complain!! )
Mutabar Shah (4 months ago)
Thanks sir it works but i got an error in debbuger that invalid path and i think that the path which i have select is correct.
Suhail Ahmad (5 months ago)
do i have to do this every time i create a new project folder to start a project
Emad Saeed (5 months ago)
thanks man, worked like a charm
TheGeeksHelp (5 months ago)
which screen recorder you are using can you tell me ?
Raktim Haldar (5 months ago)
this is very helpful video. from last few days i was unable to set up VS Code. thanks
1SoldierofPeace (5 months ago)
In the task file under "args", could you say "*.cpp" to set any c++ program or does it have to be the specific filename
Joseph Saber (5 months ago)
no you have to write "main.cpp" for example and any header file "header.h" in order for it to work
Joseph Saber (5 months ago)
thanks your steps works very well there is only one problem I can't include header files ?? I fixed this problem by adding the header files in the arg in task file the main reason why some people prefer VS Code over VS IDE is because VS Code is free and Open Source while the other costs money for commercial use
Aditya Raj (5 months ago)
VS Code isn't meant for C++. Stop wasting time
S0urc3C0de (4 months ago)
Like I said as well, it depends. For large projects, you're right. There, Visual Studio, or any other true IDE, is probably a better choice. But for smaller projects, VSCode is more than enough. I've written a couple of smaller libraries using it and never regretted it. However, note that, in fact, you don't actually NEED an IDE for anything. I've written a fairly large application with a couple of sub-libraries using VIM only. It really depends on the project and on the programmer :)
Aditya Raj (4 months ago)
I know about all this, this is why I said it isn't meant to be an IDE for C++. Even the talks from Microsoft about VScode say that it is only meant for quickly reading the code and not for developing projects in C++. Also, if you have an SSD on your system, the time it takes for VS to open is negligible. So why would you use VScode for C++ Apart from this, if in future they improve support for C++, then I'm all in. I love it as an editor for web applications. But for C++, it isn't a good option.
S0urc3C0de (4 months ago)
I never claimed that it was on the same level as Visual Studio. It is a lightweight editor and for many, that is all they'll ever need. If you need more, then that's fine. Visual Studio is more feature rich than VSCode but that does not implicate it being "better". Everyone needs to decide for themselves what they want and what they need. I just want you not to tell people what they need. Decide for yourself and let others do the same. Also, conveying your opinion through insults is not a prove of high intellect.
Aditya Raj (4 months ago)
S0urc3C0de It is meant to be a light weight editor not a complete IDE for c++. Further, if in future they improve it enough to function like a complete IDE then well and good. Also, for windows visual studio is way better than the lightweight version and i've given them both a shot so I know what I am talking about you idiot.
S0urc3C0de (4 months ago)
VSCode is meant to be everything you want it to be. The C/C++ extension works wonderfully once you set it up correctly. Don't tell people what is and what is not if you don't know what you're talking about!
Jorge Morales (6 months ago)
Bueno y aqui estoy , complicandome la vida :v
Maxrbr24 (2 months ago)
Daniel Lozano  Pordrías copiar la carpeta "vscode" y pegarla en cada proyecto
Daniel Lozano (5 months ago)
Tocara hacer eso, gracias!
Jorge Morales (5 months ago)
Daniel Lozano aún no lo hago funcionar por ahora lo que hago es llamar mediante Command line g++ y compilo manual
Daniel Lozano (5 months ago)
Jajaja, oye de casualidad has encontrado una forma para no tenerlo que hacer cada vez que quieras un nuevo proyecto?
Emad Alkhuja (6 months ago)
Thanks man!

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.