Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
100

C++ FULL Begginners Course!

JustAWalrus
JustAWalrus

C++ FULL Beginners Course.

Hello, I am

@Wuru
and this is my C++ FULL Beginners Course.

I know

@HahaYes
already did one but I wanted to do a more in-depth anti-cycle-squeezing one.

Disclaimer!

This course is accelerated. Meaning it is meant for C#, C, Python, Java, etc. devs and will not teach you what a variable is for example. It will teach you how to make one though.

So let us begin.

Table of contents.

  • Why C++?
  • Setup
  • Quick comment overview
  • 1: Overview of a basic C++ file
  • 2: Hello, World!
  • Basic data types
  • 3: Variables
  • 4: Getting user input.
  • 5: Functions in C++
  • 6: IF Statement
  • 7: WHILE Loop
  • 8: FOR Loop
  • OOP Terminology
  • 9: In-depth OOP
  • 10: Structs
  • 11: Pointers
  • 12: .h files
  • Falts of C++
  • Where to go from here.
  • Conclusion
  • Bibliography

Why C++?

Pretend C is like a muscular guy who also happens to not be terribly bright.

C++ is like his nerdy but still muscular brother.

Still very strong and fast but not a pain to work with and more controlable.

C++ was invented by Bjarne Stroustrup in 1979 at Bell Labs as an extension to the C programming language.

He wanted an efficient, fast, and flexible language that was similar to C that also provided high-level features to organize your program.

Many languages are based off of C++ so it's a nice language to learn.

Setup

For your setup I would reccomend having the repl for this course open and checking out the C++ files there and trying to run them. For this I made it so you can run it and a bash script will execute that will prompt you which file you want to execute and run that file.

Anyway, use repl.it for now.

Quick comment overview.

This is just so that you understand when in the course I am using a comment.

A 1-line comment is used by putting a // before the comment.

// This is a one line comment.

A multi-line comment can be made by putting a /* at the start and a */ at the end a end of the comment.

/* This is a multi-line comment. Cool huh? */

Overview of a basic C++ file.

This section is going to use the 1.cpp file in the course repl.

This is the most basic of C++ files:

int main() { return 0; }

And all it does is end the program with an exit code of 0.

To see this exit code in repl.it go over to your side terminal and (after your code is done running) type echo $? to see the exit code of the last run program.

Let's break down the code.

int main() { }

Above is the main function. Your program needs one to run. It is called in the executable that your compiler will generate.

Functions in c++ have this syntax:

<return type> <name>(<args>) { <code> }

You can also put the first bracket next to the last paren like shown in the main function example.

The return type is what the data type is that the function returns.

The name is always alphanumeric but the first character can only be alphabetical it also cannot be a reserved keyword like int.

The args don't matter for this section.

And the code is where your code inside the function goes.

The return is seen in many langauges. We are returning an int like said in the return-type.

We return a 0.

And each line of code in c++ must end with either a semicolon or bracket. In the case of regular code it must end in a semicolon.

1: Hello, World!

This section is going to use the 2.cpp file in the course repl.

To print text to the screen we must use a library called iostream.

To include libraries from the standard c++ library set in our code we can do:

#include <libname>

In this case we do:

#include <iostream>

This is known as a preprocessor and we will use more of these later.

Then we define our main function:

#include <iostream> int main() { return 0; }

Then in that function we can type our line of code to print:

#include <iostream> int main() { std::cout << "Hello, World!\n"; return 0; }

Let's break the print down.

std is a container that happens to hold cout. std is known as a namespace.

We then put :: to tell C++ that we are refering to something in that namespace.

Then we put cout to tell c++ we want to use cout.

Then we put << because that is couts syntax.

We seperate our different things to print like this.

Then we put our hello world with a newline.

And lastly, our semicolon.

We run and get this output:

Hello, World!

Data types

C++ is statically typed meaning that once you declare a variable you cannot change its type.

C++ has way too many data types for us to talk about right now.

We will discuss a few and their different properties.


Chars

Chars have 's around them and they are a single unicode character.


Strings

Strings need to be included via #include <string> and they have "s around them they store multiple char types.


Ints

Ints are integers.


Doubles

A double type variable is a 64-bit floating data type.


Variables

This section is going to use the 3.cpp file in the course repl.

To declare a variable we use this syntax:

<type> <name> = <value>;

The type is pretty straightforward.

Here are the identifiers for the types we discussed last section.

  • String - std::string
  • Int - int
  • Char - char
  • Double - double

The naming protocol is the same as for the functions.

The value is also easy.

Check out 3.cpp for a few examples.


Declaring a variable without an immidiate value.

We can use the syntax:

<type> <name>;

You cannot use this variable yet though.


Getting user input.

Short section but still important.

To get user input we type this:

std::cin >> <var>;

We have the same general idea as cout. We have our std:: and our name (in this case cin) then instead of <<s we put >>s and then we put the name of the variable we want the user input to go to.

We also have to include again.

Check 4.cpp for more details.

Functions in C++

So far the only function we have worked with has been the main() function.

Functions are like little containers of code.

<return type> <name>(<args>) { <code> }

That is the syntax for a function in C++.

So we have discussed data types in c++. The return type can be any of these.

It can also be a secret type.

This type is called void.

This means that the function returns nothing.

Lets declare a function together!

char giveBackChar(char x) { return x; }

Hopefully your functions will be more useful.

Check 5.cpp for more info.

READ THIS!!!

Hey, so I'm making this a two-parter. This is part 1 and part 2 will come out soon!

2 years ago

Voters

Comments

TopNew
1
DakotaWhidden
DakotaWhidden

People, are such dicks. Thank you for sharing your information. This was helpful to an extent.

10 months ago
1
liltaco
liltaco

Two very important parts of C++ you missed are the built-in STD types like std::vector, and the smart pointers like std::uniqueptr and std::sharedptr.

2 years ago
1
programmeruser
programmeruser

I've been trying C++ and some parts seem kind of cleaner but C still has its advantages e.g. smaller, faster programs since it's more low level
Edit: http://www32.cplusplus.com/forum/lounge/265787/

2 years ago
1
Highwayman
Highwayman

Nooo C is NOT lower level why does everyone think this it’s ridiculous just because C++ is more feature-full does not mean that it has to be higher level!
Ugh. I’m sorry really if you are disturbed but this has got to stop why does everyone think this it’s starting to piss me off


@TheProgrammer3

2 years ago
1
DungeonMaster00
DungeonMaster00

when will second part come out

2 years ago
1
JustAWalrus
JustAWalrus

Idk, I'm kind of quitting repl.it.

@nk1rwc

2 years ago
1
DungeonMaster00
DungeonMaster00

@Wuru
bye then good luck i will remember you for you're good tutorials

2 years ago
1
HahaYes
HahaYes

smh what is this cycle squeezing tutorial

2 years ago
1
Wuru
Wuru

It's too long to be cycle squeezing. Please stop acting like you are the one to choose who has good tutorials and who doesn't. If you care so much about them, then please add by making your own better (in your view) tutorials rather than taking. Thank you :-)

@HahaYes

2 years ago
3
Jakman
Jakman

I still rock with C.

2 years ago
1
DynamicSquid
DynamicSquid

@Jakman
I've been doing C for a couple days now and it's actually kinda cool

2 years ago
1
Jakman
Jakman

@DynamicSquid
Join us. We like it because of the few features. In cpp there are several solutions to a problem that could easily be solved with one only solution in C.

2 years ago
1
DynamicSquid
DynamicSquid

@Jakman
yeah but that's why i like c++ since it gives you a lot of features to do something. you can really do whatever you want. like I have no problem writing code in c, but I wish it's had some features that c++ has, like templates

2 years ago
1
Jakman
Jakman

@DynamicSquid
you can always make your own C compiler and give it whatever features you want.

2 years ago
1
programmeruser
programmeruser

@Jakman
I just tried C++ today (I usually use C) and it feels kind of easier to work with

2 years ago
1
Jakman
Jakman

@TheProgrammer3
yeah. I can get that. it has some nice features

2 years ago
1

You can always make your own set of functions [email protected]

1 year ago
4
xxpertHacker
xxpertHacker

And each line of code in c++ must end with either a semicolon or bracket. In the case of regular code it must end in a semicolon.

*Cough, each statement must end with semi-colon.

Chars have 's around them and they are a single unicode character.

I wish. Yeah no, they store ASCII. You're looking for u8'C'.

You didn't differentiate between types and classes. :/

Strings need to be included via #include and they have "s around them they store multiple char types.

Not true at all. C has strings. C has quote surrounded strings. C++ has the exact same strings.

auto x = "Hola, Mundo!"; // C-String auto x = "Hola, Mundo!"s; // C++ std::string auto x = "Hola, Mundo!"sv; // C++ string view (Preffered)

Also, C++ has two different function declaration syntaxes:
The one you mentioned, of course:

()
{

,[object Object], ,[object Object], ,[object Object],[object Object]
2 years ago
5
JustAWalrus
JustAWalrus

Hey there buddy, if you care so much about beginners then why overwhelm them with this very rarely used stuff that they may never need. Okay, the ASCII instead of unicode argument. Fine, that is a solid point. But what beginner is going to use this other way to declare a function. And that is just an example. And for your other dumb rant going on about the semicolon thing, if you actually read instead of ranting on about it. You would see that I said that it needs to end in a semicolon or a bracket. A beginner wont know the terminology. They have no idea what a damn statement is.

@xxpertHacker
knows nothing about writing tutorials. Zip, Zilch, Nada. And that is not even the beginning of your rhetoric.

2 years ago
2
xxpertHacker
xxpertHacker

@Wuru
You said this is for people coming from other languages, not new programmer level beginners, that is whom I was referring to. Are you suggesting that one who knows C# to an intermediate level doesn't know what a statement is!? You have already assumed that they know what a variable is, but not a statement? That's nonsense. Those are both require bare minimum competence in programming with a C-family language. The only people that I could expect to have a problem with understanding this would be those coming from Python, which would still be very easy to explain to them. C++ isn't a beginner language, but what you have given couldn't even help someone set up a program on their own. You barely gave any explanation on the core of that which makes C++... well, C++.

2 years ago
1
JustAWalrus
JustAWalrus

I don't have the time to continue this pointless garbage so I will leave you with this: what I said is much easier to understand than the whole statement thing and also gets the same job done as the statement thing.

@xxpertHacker

2 years ago
1
Kirit0
Kirit0

@JustAWalrus
idk why people are bashing. It seems to work great for me, as my only known lang is python. So all these people who know more languages, who may i add wasnt the targeted audience, saying that your all wrong, you cant just go into something describing every little detail. the human brain dosnt proccess information fast enough to keep up with that in a total of 5 minutes of reading. so good job to you my dude

2 years ago
1
xxpertHacker
xxpertHacker

@Kirit0
Explaining every last detail is the last thing you should do, I did most of that as a joke. But in truth, it's just that this doesn't teach anything at all. It gives a few examples, doesn't explain any of it, and walks away claiming to have taught you something. You can't begin learning C++ looking at this. I would legitimately recommend HaHaYes's C tutorials over this.

2 years ago
1
Kirit0
Kirit0

@xxpertHacker
It taught me the equivalent of print and input from python into c++. Which tbh could be enough to make a very simple text based game. Me personally as the subjected audience found it to work well for how short it was. But i see you would have a different perspective based on your experience level though so

2 years ago
1
Kirit0
Kirit0

@xxpertHacker
thanks for the recommendation though

2 years ago
1
xxpertHacker
xxpertHacker

@Kirit0
It's that I believe that one should have a depth of understanding, this is super shallow. I don't think you need to know the finest details of stuff, but at least a moderate comprehension of what you're working with. Now if this were just the beginning and in the next tutorial he explained it in more depth showed alternative, explained what everything does, etc, then it would be far more acceptable.

But when you say it's intended for those who already know what programming is, that's when it's too shallow.

For example, does it explain why you do std::cin >> x; instead of std::cin << x; or std::cin(x);? What does << even do? That's one of the key features of C++, that needs to eventually be explained. No, it doesn't need to be a day one thing, but it should be pointed out.

2 years ago
1
honse
honse

tbh HahaYes's tutorials are kinda bad. ik

@JustAWalrus
's C++ tutorial isnt wonderful but ya gotta cut him some slack. He made tons of great tutorials that ive read before he left repl.it (i use this site to read tutorials) and this was kinda his last one (maybe he got burnt out or something) anyway, happy coding!
@xxpertHacker

2 years ago
1
xxpertHacker
xxpertHacker

@honse
Good luck, I fully support trying to take whatever you can from a tutorial when you have the opportunity. It may not be great, but at least it's something. That goes to both HaHaYes, and JustAWalrus.

I'm actually going to go check out their ASM tutorials very soon and see if there's anything I can actually get out of them or apply to what I know.

2 years ago
1
Kookiez
Kookiez

@xxpertHacker
you mean HahaYes's C++ Tutorials, not C. I think it was CodeLongandPros who made the C one... IDK

2 years ago
1
xxpertHacker
xxpertHacker

@OrangeJooce123
Oh yeah, it was, oops; I meant "C++" in that case.

2 years ago
1
xxpertHacker
xxpertHacker

Ugh, .h files, in C++!?

2 years ago
1
firefish
firefish

cough C course? coming soon? couch

2 years ago
1
Load more