Likes: 0
Results 1 to 3 of 3
Thread: C++ Scripting Tutoial #1
-
07-02-09, 10:30 PM #1
C++ Scripting Tutoial #1
Register to remove this adCode:#include <iostream> using namespace std; int main() { cout << "Hello World!\n"; return 0; }
This is usually the very first program people start out with when they begin doing
programming.
Im going to explain what each line does
Code:#include <iostream>
the compiler to do something before it starts compiling, in this case it tells the compiler
to find iostream.h and include it in this .cpp file.
When a compiler includes something, it means that the .cpp file can use functions that the
.h file declares.
Code:using namespace std;
similar to each other in that they both are a group of functions, but they are different.
Namespaces are a group of function identifiers, in this case std, this line tells the
compiler that the .cpp file is using the std namespace so every time a function has a std
identifier there is no need to use it, in this case cout is actually std::cout, but becuase
we are using the std namespace there is no need to "identify" cout with std.
Code:int main()
you have this, the program WILL NOT work if you don't have this function.
the int before the main() is what must be returned when the function ends, in this case an
int which means an integer, there are other things im sure you have seen, void, uint32, and
others.
void basically means that the functions will return no value, uint32 means the function will
return a value of an uint32, exactly what a uint32 and other datatypes will be explained in
another tutorial.
Code:{
executed.
Code:cout << "Hello World\n";
the same thing, but for the sake of this tutorial and simplicity I chose to use cout.
the << is an output operator, everything afer is is written to the cout function, so the
cout function can output the text to screen.
the quotations signify a string, what exactly a string is will be expalined in another
tutorial.
the \n is simply called an escape character, this certain one writes a new line, so if i
were to add more text it would be written on the line after Hello World!
Code:return 0;
Code:}
of teh function!
Code:;
need this, like an if, for, and others
If you have any questions please don't hesitate to ask!
There will be more tutorials!!!!
Created by: CoolManBob
› See More: C++ Scripting Tutoial #1
-
08-02-09, 12:30 AM #2
Don't mean to be a bother..
I don't mean to be a bother but there is so much hear that is kinda misleading. Hope you take this as a friendly correction
Starting with pre processor. You refer to it as a symbol. It is referred to as an operator. You also talk about how in your case your including iostream.h file. You should make sure to add that these are library files and the < and > symbols that surround iostream are to tell the specific compiler to locate that header file in its library folder.
Then the int main() is pretty much correct other then the fact that you only need int main() for executable files.. But that is a completly different subject and didn't need to be added so your good on that part
For curly brackets "{ }" you should explain the code within these brackets are called blocks of code.
Sorry for being such a correction freak.. I just like to help people and make it esier for people to understand stuff.
For cout and and displaying text. I really urge people to explain it for what it really is. Think of cout as Console Output and cin as Console Input. It is so much easier to understand and 100 times quicker to explain.
return 0; means to return a value of 0 which tells the function that no errors occured during the compile & run of the program.
-
08-02-09, 04:05 AM #3
Register to remove this ad
Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread
Visitors found this page by searching for:
Nobody landed on this page from a search engine, yet!
SEO Blog