DEV Community

Developing C++ with Visual Studio Code

ACharLuk on August 01, 2018

Welcome to my first post! I will be showing you how I develop C++ using Visual Studio Code along with the C++ and Easy C++ Projects extensions. ...
Collapse
 
larssonted profile image
Ted Larsson

I´m a complete beginner at coding and is looking for a nice and simple IDE to use, I´m currently using ms visual studio but i want to find a more lightweight IDE for storage reasons. I tried vscode a bit, i managed to install a compiler but then all of a sudden i needed to edit json files and such things and i have no idea how to do that. I looked at youtube videos but learning all that AND c++ was too much information at once. I´m learning to program in c++ at the moment and will be moving on to c# in a few weeks, does this method make it easier to compile and debug projects? or is there another IDE you can recommend?

Collapse
 
acharluk profile image
ACharLuk

If you know how to install your compiler it is much faster to develop with VSCode and this extension imo, it has intellisense and automatic project creation!

Collapse
 
larssonted profile image
Ted Larsson

I've managed to install the compiler but when it comes to configuring .json files and such things I'm lost.

Thread Thread
 
acharluk profile image
ACharLuk

If you create the project using Easy C++ you don't need to set up any json file yourself, you press F1, search for Easy C++ create new project and it will set everything up. A couple of buttons will show up at the bottom bar for building and running the project.

Thread Thread
 
larssonted profile image
Ted Larsson

Allright I'll look in to it 😊👍🏻

Collapse
 
arby3k profile image
Arbab Ahmed

I can't seem to figure out why I keep getting the following error when trying to run just the "hello world" project Easy C++ makes.

"The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it."

Collapse
 
pianocomposer321 profile image
pianocomposer321

I think that's because the template that Easy C++ Projects makes doesn't include a "return 0" statement, so the shell never knows that it exited successfully. I prefer C/C++ Project Generator to Easy C++ Projects, and would reccomend trying that.

Collapse
 
abhisingh127 profile image
abhisingh127

I get the same error

Collapse
 
abhisingh127 profile image
abhisingh127

can someone help me please?
whenever I click at build and run, It shows error like permission denied and then says error at int main()

Collapse
 
acharluk profile image
ACharLuk

Hey! Can you give us some context? What OS are you using? Are the folder permissions correct?

Collapse
 
abhisingh127 profile image
abhisingh127

Actually it was a problem with permissions. I am using Ubuntu 19.04 . The executable permission was not given.

Thread Thread
 
acharluk profile image
ACharLuk

I'm glad you got it solved! I'll take note of this to see if it is isolated to Ubuntu 19.04 or I should upload a fix, thank you for the info!

Thread Thread
 
abhisingh127 profile image
abhisingh127

Actually. It was due to my own ignorance. I forgot about the file permissions in linux. All you need to do is add the executable permission using the chmod +x command.

Collapse
 
goodmansoul profile image
GoodManSoul • Edited

This is not a complete guide to begin code with c++ language. Sad but true. Default C/C++ extension doesn't provide full compilation support. Needs gcc compiler...

  • not all libraries will be supported by simple gcc config (like "thread" library ...). For those who have an error -> download MinGW and add it to the PATH. +Have a good time
Collapse
 
txai profile image
Txai

Great post! I was looking for a substitute for eclipse-cdt. Do you think vscode can be a good comperitor to eclipse?

Collapse
 
acharluk profile image
ACharLuk

I was an Eclipse user and never went back when I changed to VS Code!

Collapse
 
ash1eyish profile image
Ashley Maria

I've used both and personally prefer VS Code.

Collapse
 
pianocomposer321 profile image
pianocomposer321

Personally, I prefer "C/C++ Project Generator" to "Easy C++ Projects". It works without asking you confusing questions about the platform. Also, I really like "Project Templates", because you can start with the basic template from the project generator, then tweak the Makefile and includes to make a more customized template. I currently have one for SFML, because it would be a pain to have to set it up every time.

Collapse
 
d3xsky profile image
Dejan

Thanks, worked like a charm!

Collapse
 
dalerr96 profile image
DaLeR

Thanks for the post, worked perfectly on Windows 10

Collapse
 
jacobgeogeek profile image
Jacob C.

I was wondering if its is possible to debug in VS code by using the WSL (with g++ or gcc install) ?