Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Main Index FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: C++:
C++ for beginners

 

 


JaVa CoDe
Senior Member


Jan 24, 2005, 3:54 AM

Post #1 of 13 (4904 views)
Shortcut
C++ for beginners Can't Post

This tutorial for complete beginners.
Use a compiler like VC++ 6 or Bloodshed.


CODE

#include <iostream.h> //Includes iostream for I/O operations?!?!?!?!?!? LIEK

char f[50] = "Hello World!"; //Sets f to 50 character length and puts "Hello World!" in

int main() //Initialises main
{ //All code in Main goes after this
cout << f << "\n"; //Outputs whats in f then makes a new line ("\n")
return 0; //Ends the program
}//End of code for main




Hope this was helpful for people who know no C++


_____________________________________________
~Java Code
(17:38:33) <%Brody> Xavier, Taz, and Athrin are like: You fags suck at internetting.
(17:38:49) <%Brody> Ahh, go blow one, you intellectual



Infinitus
Veteran


Jan 24, 2005, 5:12 AM

Post #2 of 13 (4633 views)
Shortcut
Re: [Java Code] C++ for beginners [In reply to] Can't Post

That was somewhat confusing Java. Here is a simpler approach to the Hello World program:



1 #include <iostream>
2
3 using namespace std;
4 int main( void )
5 {
6 cout << "Hello World!" ;
7 return 0;
8 }



To start out you must learn what each part of this program does.
In line 1, we see #include.

#include is a directive. It allows you to incoporate other files you or others have created into your source code.

Next we see <iostream>. <iostream> is a standard library that is found in every C++ compiler. It deals with the input and output of your programs, such as text output to the screen as well as user input into the program. I'll explain user input in a sec. It is also helpful to know that standard library files have no file extension and are placed in < > without the .cpp extension.

In line 3 we see using namespace std; Namespaces are used to make standard libraries function correctly. When using the namespace std you are allowed to use the statements, or commands, cout and cin. Namespaces are a bit more complicated and it's best not to worry about them yet. Just besure to include "using namespace std;" when #include'ing <iostream>.

In line 4 we come to int main( void ). the first part, int, shows that when this function is complete, it will return an integer to show it has run through successfully, by standards, it should return a 0, which we will get to later in the code. The next part, main( void ), specifies the beginning of the main function. All programs have ONE main function. Most of your coding goes into this function, although you are also able to write your own functions and use them within your programs. All of the code inside the main function go inside of the brackets: { }

In line 6 the statement cout is used. cout is used to display output onto your computer screen, such as text, numbers, etc. cout is followed by two less than signs: <<. These show the direction the data is going.

cout << "Hello World!" ;

This shows that the data "Hello World!" is going to be displayed on your screen as the output.

The last important line (excluding the ending bracket for the main function) is:

return 0;

This pretty much tells the computer nothing else is going to occur inside main and to exit the function.

That is how to interpret the Hello World program. (I normally use Hullo World Tongue)

-----------------------

Things I forgot to add:

You must always end lines in your program with a semicolon (;). There are special exceptions such as int main(void) and others but generally you will need to use one.

To add comments, you can use:

//Insert comment here for single line comments

/* Insert comment here for commenting inside the statement */

/* Insert comment here for
commenting over several lines */



It is best to use the first example. It is possible to use the others but more than likely it will make your program very messy when trying to read it.


(This post was edited by Infinitus on Jan 24, 2005, 5:15 AM)


JaVa CoDe
Senior Member


Jan 24, 2005, 5:45 AM

Post #3 of 13 (4630 views)
Shortcut
Re: [Infinitus] C++ for beginners [In reply to] Can't Post

Ok thanks i made the one i posted made sense to me o well should of added more details.


_____________________________________________
~Java Code
(17:38:33) <%Brody> Xavier, Taz, and Athrin are like: You fags suck at internetting.
(17:38:49) <%Brody> Ahh, go blow one, you intellectual


Infinitus
Veteran


Jan 25, 2005, 5:59 AM

Post #4 of 13 (4622 views)
Shortcut
Re: [Java Code] C++ for beginners [In reply to] Can't Post

I'm somewhat of an amateur. Trying to perfect an Imperial to Metric and vice-versa program now. Still learning Wink. I'm pretty good with everything I've learned so far though.


JaVa CoDe
Senior Member


Jan 25, 2005, 9:31 AM

Post #5 of 13 (4618 views)
Shortcut
Re: [Infinitus] C++ for beginners [In reply to] Can't Post

Im only short bit ahead of that but i'm taking a class in it nice job!


_____________________________________________
~Java Code
(17:38:33) <%Brody> Xavier, Taz, and Athrin are like: You fags suck at internetting.
(17:38:49) <%Brody> Ahh, go blow one, you intellectual


Infinitus
Veteran


Jan 25, 2005, 10:24 AM

Post #6 of 13 (4617 views)
Shortcut
Re: [Java Code] C++ for beginners [In reply to] Can't Post

The most annoying part of this Metric to Imperial units program is trying to decide how you want the program to operate. For example, do you want the program to first ask what unit you currently know and the amount you are dealing with, and then select a unit of measurement to convert it to (this is my current game plan), or having the program give a predetermined list of unit to unit formulas and let the user press, say "1" for inches to centimeters and then type in how many inches, producing the amount of centimeters.

Gotta remember the 6P rule:

Perfect Planning Prevents P*** Poor Performance Wink


JaVa CoDe
Senior Member


Jan 26, 2005, 7:25 AM

Post #7 of 13 (4609 views)
Shortcut
Re: [Infinitus] C++ for beginners [In reply to] Can't Post

This will be helpful for beginners ill sticky.


_____________________________________________
~Java Code
(17:38:33) <%Brody> Xavier, Taz, and Athrin are like: You fags suck at internetting.
(17:38:49) <%Brody> Ahh, go blow one, you intellectual


JakeTKD
Enthusiast


Jan 26, 2005, 3:42 PM

Post #8 of 13 (4601 views)
Shortcut
Re: [Java Code] C++ for beginners [In reply to] Can't Post

Yeah, I don't know what half of that crap means lol.


_____________________________________________
http://www.xanga.com/home.aspx?user=Jake86
crossfade


JaVa CoDe
Senior Member


Jan 27, 2005, 2:41 PM

Post #9 of 13 (4592 views)
Shortcut
Re: [JakeTKD] C++ for beginners [In reply to] Can't Post

Read it these make good sense.


_____________________________________________
~Java Code
(17:38:33) <%Brody> Xavier, Taz, and Athrin are like: You fags suck at internetting.
(17:38:49) <%Brody> Ahh, go blow one, you intellectual


nadkicker69
Veteran


Feb 15, 2005, 8:18 PM

Post #10 of 13 (4475 views)
Shortcut
Re: [Java Code] C++ for beginners [In reply to] Can't Post

Here's my two cents...

To make sure that someone, even the non-programmers or even non-technical people can understand your code and what it is trying to say is this.

Try using commentary.

Commenting every little line of code you make is tedious, boring, and VERY annoying to the coder, but looking back at it, you can look with satisfaction that whoever reads your code will understand it completely, and if you have to come back to it, say 10 years later to update it or whatever, at least you know what each line's about instead of "What the hell was VarXXX for???"

Well, it works for me and everybody I tutor in programming... *shrugs*


=
I am the Jester. I make the unreal real.


Juno
Enthusiast


Jun 28, 2006, 8:53 PM

Post #11 of 13 (1726 views)
Shortcut
Re: [Infinitus] C++ for beginners [In reply to] Can't Post

Ummm can you use C++ in Frontpage, or is it only HTML and Java?


rekha
Newbie

Feb 6, 2008, 6:42 PM

Post #12 of 13 (1033 views)
Shortcut
Re: [Juno] C++ for beginners [In reply to] Can't Post

It is not necessary learn c to learn c++,if u already knows the language c than its quite easy to learn c++,but already u have no knowledge of c than u can learn c++ very easy,its concepts are different than the "c" .TO learn basic cocepts follow the easiest book.
The games can also be made in language c++


j0shk1m
Newbie

Apr 13, 2008, 9:06 PM

Post #13 of 13 (872 views)
Shortcut
Re: [JaVa CoDe] C++ for beginners [In reply to] Can't Post

Ummm....Thats just Outputting text onto a screen...can you tell me how to make it respond to typed commands? i really want to know...


Get anything you want here! It actually works.
http://www.prizerebel.com/
Things ive got so far:
xbox 360
xbox live 3 months
Dead or Aliv

 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.22 s on (CGI/1.1)