These processes are based off the basic "Hello World" program.
Code:
//
// creates a comment line. All lines beginning with "//" are considered comment lines, and do not effect the program in any way. A programmer can use these to give brief explanations of a code within the code itself.
Code:
#include < iostream>
Lines beginning with a number (hash) sign "#" are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. Basically, they tell the program to include certain library files. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.
Code:
using namespace std;
All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.
Code:
int main ()
This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function.
The word main is followed in the code by a pair of parentheses (()). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them.
Right after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed.
Code:
cout << "Hello World!";
This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.
cout is the name of the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (cout, which usually corresponds to the screen).
cout is declared in the iostream standard file within the std namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code.
Notice that the statement ends with a semicolon character (. This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).
Code:
return 0;
The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.
And your finished code should be:
Code:
//Tony's C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "Hello MPGH";
cout << "Don't hate on this, it helps.";
return 0;
}
Yes I did copy and paste some of this.
If you want the program to stay open until you hit enter, this is the code:
Code:
//Tony's C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "Hello MPGH";
cout << "Don't hate on this, it helps.";
cin.get();
}
Just change
Code:
return 0;
to
Code:
cin.get();
Its a tut from a link of the tutorial sticky thread (Yes my sentence may look difficult )
Originally Posted by xXModz
Its a tut from a link of the tutorial sticky thread (Yes my sentence may look difficult )
It is?...
[php]ess tee dee SEE aot << kwote HI end kwote Semikolon[/php]
Originally Posted by Koreans
[php]ess tee dee SEE aot << kwote HI end kwote Semikolon[/php]
What? o.O ...
Originally Posted by Tony
What? o.O ...
Read slowly boi
you also never made a newline so it would just be on the same line, so you wouldnt need 2 couts
Originally Posted by Koreans
Read slowly boi
you also never made a newline so it would just be on the same line, so you wouldnt need 2 couts
Never said I wanted it to be on a separate line. If I wanted it to be on a separate line, I would add
Code:
\n
or
Code:
endl;
Originally Posted by Tony
Never said I wanted it to be on a separate line. If I wanted it to be on a separate line, I would add
Code:
\n
or
Code:
endl;
and whyd you use 2 couts?
It's not "based" off "hello World" it is copied and pasted
Mmz, some invalid information but I'll let it fly because I'm not a dick.
The EP of a program is 'main' symbol at default for the Console subsystem, but you can change the arguments passed to the linker and make it something else. The entry point name and parameters also change when you use other subsystems, such as Native(for kernel drivers) or the Windows subsystem.
I can't find anything else wrong really, but I haven't read it all to be honest. Just the last part where you suggest you replace the return with cin.get() is a bad idea. Compilers will throw a warning because if the called routine doesn't return with a specified value, then the return value is undefined. As the return will be whatever is loaded in the eax register[well actually, that depends on the calling convention. But assuming you're using stdcall or cdecl], which could have been altered by the caller or the callee.
Anyway, a good way to remember what you've just learned is to make a tutorial regarding it. Just don't be offended when I come along and make a few corrections.
Thanks for posting it.
Jetamay is write on that should not replace return 0; :3 if your using PC and don't plan on making anything for mac or other OS you could add #include <windows.h> and use system("PAUSE"); or Sleep(9000); (9000 is just an example its in milliseconds btw) ( not usually suggested because its not standard c++ but i guess too start off why not there's an infinite amount of ways to stop your program
EDIT
by curiosity whats wrong with using 2 cout's instead of 1? i mean not in this case.. if you intended too make it in 1 sentence id suggest you put it in 1. I don't see why you would call it up 2 times but yea how taboo is using 2 cout's really? lets say some one had 200 lines to write down in cmd would it make any difference if he wrote it all in a single cout with \n\t ect... or would it be just as fast too execute 50 cout's. Sorry if this doesn't make sense...its 4:27 and i was bored working on a mini CMD side shooter and wondered if it would alter the performance of my "game" ( speed lag wise ) D:<
Uhhhh is it just me or doesnt cin.get(); no longer pause after using cin before it? Also this tutorial truthfully is underwhelming... You basically MAYBE taught someone how to print to screen.... This tut (and ones like it) are the reason mpgh has many leaches.... truthfully after reading this all I would be able to do is write that program or change the txt it displays and IF I had read the entire thread I would know endl;
Just saying for the skill level this tutorial is targeted at its not exactly sufficient...
Nontheless thank you for a contribution to our community and at least an attempt at educating the FR00BZ0RS
Eh, can someone edit my post, I misspelled iostream in the first code. :/