Basic C++

by learncppwithshay in Circuits > Tools

1505 Views, 20 Favorites, 0 Comments

Basic C++

CPlusPlus.jpg

Today you will learn Basic C++ in 5 minutes.

What You Will Need

terminal.png
Screenshot 2016-02-29 at 12.21.58 PM.png

A Mac with terminal, or on any computer go to https://www.codechef.com/ide on any computer. And your imagination

Only If You Are Starting in Terminal, Getting to the Editing Platform in Terminal

create-a-new-folder-mac.png

The first thing you will need to do is make a folder on your desktop, call it anything you want, this is where your c++ projects will go.

Getting to Your New Folder From Terminal, ONLY FOR PEOPLE WITH MACS

Now, you will need to open terminal and type in this, cd ~/Desktop/[Name of the folder] pwd

Getting to Nano(fancy Word for Editing Software in Terminal), FOR MAC PEOPLE ONLY,

Congrats you are now in your folder on your desktop. now type in nano test1.cpp,

this will create a file named test1.cpp and bring you to the editing software for editing test1.cpp

Putting Your Heading/ Starting Code In, FOR EVERYBODY,

Screenshot 2016-02-29 at 12.25.00 PM.png

now that you have your nano up in terminal, and for those of you not on a mac, in codechef.com/ide. You have to insert a heading, in codechef, they already put in for you, but it is good to know and also nano does not start with it.

This is what you should put in,

#include <iostream>

using namespace std;

int main()

{

return 0;

}

, this is what will make your code run.

Making Hello World

Now that we have our starting code, lets start the real program.

#include <iostream>
using namespace std;

int main()

{

//everything in the brackets is code, but when you put two slashes the code ignores that line insert the codebelowthis

cout << " Hello World" << endl;


return 0

}

How to Run It

For those of you in codechef, press the run button in the bottom right. And the output should be Hello World. But for those of you in nano, type in the following:

do control o,

press enter,

do control x,

type in in the regular terminal not nano, type in make test1,

than type in ./test1

it should than run