EverEffects Backup Forum
Welcome To We Can't Program Forums, Please Log In To Access All Forums.

Enjoy Your Stay

- Staff
EverEffects Backup Forum
Welcome To We Can't Program Forums, Please Log In To Access All Forums.

Enjoy Your Stay

- Staff
EverEffects Backup Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

EverEffects Backup Forum

Designers World
 
HomePortalLatest imagesRegisterLog in



 Basic Syntax and functions [C++] Resize


Share | 
 

 Basic Syntax and functions [C++]

View previous topic View next topic Go down 
AuthorMessage
Fred
Staff
Staff
Fred

Posts : 33
Join date : 2010-05-27
Age : 31
Location : Oklahoma

Basic Syntax and functions [C++] _
PostSubject: Basic Syntax and functions [C++]   Basic Syntax and functions [C++] EmptyThu Jun 03, 2010 2:41 pm
Here is my example of Basic Syntax and Functions. You can proceed to this tutorial

Code:
#include <iostream>
int main()
{
using namespace std;
cout << "Hello i am Bob.";
cout << endl;
cout << "Nice to meet you Bob." << endl;
system( "pause");
return 0;
}
_____________________________________________________________

So lets break these down.

Now the "#include <iostream>" is a preprocessed directive and what it does is just process the source file

The "int main()" is a title header. Int means Integer which is our Integer function. Main is our function title name. And the () means your starting your function Sequnce.

Now if you focus to the braces which are these "{ }". These braces is gonna be your braces statements which you have to write something between it which is your writing instructions for the function also called the "body". For example....

Ex.
Code:
#include <iostream>
int main()
{
<<<Write something between these Braces.
}
And also every state ends with a semi Collen, Which means this symbol----->;

Now right under the "int main()" function is called "using namespace std;". So write it down and what it means is means, it is telling c++ the basics of standards and other stuff. Also here is a example of it.....

Code:
#include <iostream>
int main()
{
using namespace std;

}

Now since we have our first model of Function, lets make some funny messages or something like that. Ok first lets put under the "using namespace std;" called "cout" or C-OUT which shows a basic output on the screen, also means script lines that is my way of saying it. For example......

Code:
#include <iostream>
int main()
{
using namespace std;
cout

}

And then we add two less signs that look like this "<<". Here is another example where to put those two less signs

Code:
#include <iostream>
int main()
{
using namespace std;
cout <<

}

After you put "cout" press the space bar then type the two less signs "<<". And the two less signs mean "insurgent operator"(Sorry i forget how to spell the first word).

Ok we have to make something up or lets output, so press space bar then type a open quotation mark that looks like this------>"<------. Here is a example of it.

Code:
#include <iostream>
int main()
{
using namespace std;
cout << "Hello i am Bob."; <------Also this sentence right here is called a statement.

}

Also anything you type in your quotations is outputted in your screen, and you will see. And also always end a semi Collen every time you end up a sentence.
So now we gave it a instruction now do it. so lets recap

cout << "Hello i am Bob."; <------Right here you got your string text that's inside of quotation marks, and our two less signs that is our operator.And also the "cout" you need to output off the screen. It is like typing a email or writing a letter. So nothing fancy just plain text.

Next thing i will show you to make a new line so let me show you a exmaple

Code:
#include <iostream>
int main()
{
using namespace std;
cout << "Hello i am Bob.";
cout << endl; <-------And remember end it with a semi collen or ;

}
Now the "endl" means endline and you might think the "l" is a "1" but it is actually a "l" so don't be confused. Also this means you finish your first statement, now you have to create a second statement or another line. Here is my example....

Code:
#include <iostream>
int main()
{
using namespace std;
cout << "Hello i am Bob.";
cout << endl;
cout << "Nice to meet you Bob" << endl; <-------Right here is your second sentence or your output

}
Now make another sentence and type "cout" space bar, then two less signs "<<", put a quotation mark--->", then type a message and end it with another quotation mark, press space bar, then type two less signs, and then press space bar and type "endl" and end it with a semi collen.

Ok now you have a useful function. Before we "execute", we have to type "system("pause");". So here is a example, where to put it

Code:
#include <iostream>
int main()
{
using namespace std;
cout << "Hello i am Bob.";
cout << endl;
cout << "Nice to meet you Bob" << endl;
system("pause"); <-----Right here
}

And what it does is stop and look to our function and running it. Without this of course. And the next thing you have to do is type "return 0;" and what it does is the main end of your function. The zero means you have done your project or something.

Now in your C++ program, Click on "save" by clicking on "File". After go "Execute" and click "Compile & Run". And after that it will check some errors and run your program. And as soon if the black box shows up, you have no errors but if you do have errors C++ will show you. Now in the black box it will say.....

Hello i am Bob
Nice to meet you Bob
Press any key to continue . . . _

Also without the "system("pause");" or remove it. The black box will flash for less than 1 second or that means you fail. So make sure you have that "system("pause");"

Thank you for reading this tutorial, and i hope this helps
Back to top Go down
http://wcpforums.friendhood.net
 

Basic Syntax and functions [C++]

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
EverEffects Backup Forum :: C/C++/C#/VisualC++-
Jump to:  


   [Valid RSS]





Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com