tools:cplusplus
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tools:cplusplus [2025/09/30 22:44] – external edit 127.0.0.1 | tools:cplusplus [2025/10/12 10:50] (current) – Humphrey Boa-Gart | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{wst> | + | # |
- | + | ||
- | ====== C++ ====== | + | |
- | + | ||
- | If you didn't see the [[tools:c|C]] tutorial, then go read it, or at least read the first paragraph. If C is fucked beyond belief, better grab your ass and prepare for C++, as the developers double-fucked it by adding more complex syntax and shit. | + | |
- | + | ||
- | ===== About C++ ===== | + | |
- | + | ||
- | C++ was developed around 1979 and was designed as a "step further" | + | |
- | + | ||
- | ==== C or C++ ==== | + | |
- | + | ||
- | Short answer: C++. | + | |
- | + | ||
- | Long answer: It's more complicated than that. Thing is, C is so damn flexible and good enough that you'll probably won't need any more than that in your programming needs, and having a relatively easy syntax that's not difficult to learn. However, if you want things a tad more extended for your work, in exchange to learning a bit more and preparing your brain, and, as a bonus, getting a kick out of the intellectual challenge that C++ presents to you, then that's the programming language you would like to learn. | + | |
- | + | ||
- | tl;dr: If you're lazy and won't do a lot of shit, pick C. If you want the challenge and yet don't know what to code, pick C++. **Do not try to learn both. Well, try, thing is it can be easier if you focus on only one.** | + | |
- | + | ||
- | tl;dr-ing the tl;dr: **Pick C++ and shut the fuck up.** | + | |
- | + | ||
- | ===== How do I started lerning ===== | + | |
- | + | ||
- | First of all, you'll need a compiler. Find one at the C tutorial; I use DevC++, although it's a tad outdated and such. | + | |
- | + | ||
- | ===== Okay, let's go ===== | + | |
- | + | ||
- | ==== 0.- Starting the program ==== | + | |
- | + | ||
- | Nearly every script made in C++ will start like this: | + | |
- | + | ||
- | < | + | |
- | #include < | + | |
- | + | ||
- | using namespace std; | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | The first line calls a preprocessor. In layman' | + | |
- | + | ||
- | The "using namespace std" it's telling the program that it will use functions contained in the standard library. Knowing this doesn' | + | |
- | + | ||
- | **VERY IMPORTANT BULLSHIT: ALL FUNCTIONS END WITH A SEMICOLON (Except, well, those where I don't put one). IF YOUR CODE FAILS AT COMPILING ALWAYS CHECK FIRST IF YOU HAVE ALL THE SEMICOLONS PROPERLY PLACED.** | + | |
- | + | ||
- | the "int main()" | + | |
- | + | ||
- | The {} mark a code block. The { marks the beginning of the code block and } marks the end. That's where the code goes. | + | |
- | + | ||
- | With this shit learned, we can go to the next level. | + | |
- | + | ||
- | ==== 1.- Printing crap to the screen and such ==== | + | |
- | + | ||
- | In most of your programs, you (or the user who's running it) would like to know what's going on in the application. This is where the cout function gets in. | + | |
- | + | ||
- | < | + | |
- | #include < | + | |
- | using namespace std; | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | cout<<" | + | |
- | cin.get(); | + | |
- | return 0; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | The cout function prints stuff to the screen. The syntax goes like this: cout<<" | + | |
- | + | ||
- | The cin.get() function is a very handy tool. What it does is wait for the user to press the ENTER key before going with the code. This is because when you compile it without the cin.get() function, it will open and close very fast for you to actually read the text that was printed by cout. | + | |
- | + | ||
- | When the program finished with int main() (That means, it gets to " | + | |
- | + | ||
- | < | + | |
- | #include < | + | |
- | using namespace std; | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | cout<<" | + | |
- | cin.get(); | + | |
- | return 0; | + | |
- | cout<<" | + | |
- | cin.get(); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | With the return function, the program will never display this simple (Read: Lame) easter egg, which consists in the "lol easter egg" being printed into the screen. Without the return function in the script, it will show it, and then end the code. | + | |
- | + | ||
- | === 1-A.- Other simple stuff === | + | |
- | + | ||
- | Please take a look at this motherfucking code: | + | |
- | + | ||
- | < | + | |
- | / | + | |
- | /*LOL CODE LOL CODE LOL CODE LOL CODE*/ | + | |
- | / | + | |
- | #include < | + | |
- | using namespace std; | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | cout<<" | + | |
- | cin.get(); //This shit makes the program wait until the user presses enter | + | |
- | return 0; //This shit terminates the program | + | |
- | cout<<" | + | |
- | cin.get(); // | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | First: What's the crap I added? | + | |
- | + | ||
- | Those are called comments. Those comments won't affect the code whatsoever but show the comments to whoever is reading the code. It's useless in this kind of little scripts but in large scrips it would be useful to know what are the functions doing in case it seems too confusing or anything. You can always use it to hide a message or whatever, like the Win98 developers did when sending pieces of code to each other. Thing is, the compiler will put them in the .exe but it won't affect it in any way. | + | |
- | + | ||
- | There are two types of comments: The standard, which begins with a < | + | |
- | + | ||
- | Second: What's the \n thing? | + | |
- | + | ||
- | When the program prints out a string (String: A piece of text), anything else that is printed will go inmediatly after the text. So if we happen to have to cout functions and we don't put the \n, we'll have something like this: | + | |
- | + | ||
- | this is text one.this is text two. | + | |
- | + | ||
- | With \n (Newline), the " | + | |
- | + | ||
- | this is text one. | + | |
- | this is text two. | + | |
- | + | ||
- | Having exactly what we wanted. | + | |
- | + | ||
- | ==== 2.- If statements ==== | + | |
- | + | ||
- | This one is relatively simple, but regarding syntax is quite a step from cout. | + | |
- | + | ||
- | The if statements do the following: If a certain condition is true, then a piece of code is executed. Then you can add an " | + | |
- | + | ||
- | But first, you need to remember the following " | + | |
- | + | ||
- | < LESS THAN | + | |
- | > GREATER THAN | + | |
- | >= EQUAL OR GREATER THAN | + | |
- | <= EQUAL OR LESS THAN | + | |
- | == EQUAL TO | + | |
- | != NOT EQUAL TO | + | |
- | + | ||
- | It's the classic mathematical bullshit you learn in high school, so it won't be really a big deal to remember them. | + | |
- | + | ||
- | === 2-A.- Starting up === | + | |
- | + | ||
- | Now, what is the syntax of the if statement? | + | |
- | + | ||
- | if (Stuff to compare is TRUE) { | + | |
- | (Block of code to execute if condition is true) | + | |
- | } | + | |
- | + | ||
- | An example of this would be: | + | |
- | + | ||
- | if (3 == 3) { | + | |
- | cout<<" | + | |
- | } | + | |
- | + | ||
- | Some argue that | + | |
- | + | ||
- | if (Shit_to_compare=TRUE) | + | |
- | { | + | |
- | (Block of code to execute) | + | |
- | } | + | |
- | + | ||
- | Is better than writing | + | |
- | + | ||
- | if (Shit_to_compare=TRUE) { | + | |
- | (Block of code to execute) | + | |
- | } | + | |
- | + | ||
- | Protip: It's the same. It will do the exact same thing without a single compiling error. So it's up to you to decide which one you prefer. | + | |
- | + | ||
- | === 2-B.- ELSE/ELSE IF statements === | + | |
- | + | ||
- | This one does exactly what it's supposed to do. The first one executes a piece of code in case the if statement doesn' | + | |
- | + | ||
- | "Does X equals Y? If so, print to the screen that X equals Y. ELSE, print to the screen that X does not equal Y". | + | |
- | + | ||
- | (Will work later) | + | |
- | + | ||
- | + | ||
- | {{tag> | + |
tools/cplusplus.txt · Last modified: by Humphrey Boa-Gart
Find this page online at: https://bestpoint.institute/tools/cplusplus
Find this page online at: https://bestpoint.institute/tools/cplusplus