[C]hosen-1 (04-13-2010)
Lesson #2 - Basic Output
Today we are going to be looking at the acts of output.
If this doesn't seem clear to you at the moment, don't worry. You can always come back and re-read it once you have done some practical.
The first thing your going to do is output "Sup Bitches" onto your screen.
So start a new project (ctrl + shift + n) and type in (DO NOT copy and paste as you will learn it better if you type it):
Now press F9 to compile and run it. A window will come up asking you to save it. You must change the file extension from .c to .cpp then save it and continue. The result will look like this.Code:#include <iostream> using namespace std; int main() { cout << "Sup bitches"; return 0; }
[html]Sup bitches[/html]
Now lets dissect that code.
#include <iostream>: Standard header needed for outputting and inputting streams
using namespace std: Explained as simply as possible, namespaces allows us to group a set of global classes, objects and/or functions under a name.Namespace std contains all the classes, objects and functions of the standard C++ library.
int main(): Initiates the funtion main, which is the main function of the program. Think of it as the trunk of the tree.
{ CODE }: The coding of int main() goes between the parentheses
cout: Stands for console output
<<: The << operator inserts the data that follows it into the stream preceding it.
"TXT": What to output onto the screen.
Return 0; Returns the function to the value 0
; All commands end in a semi-colon
But what happens if you want to end the line, and start what you next write on the line below? No, you do not have to do spaces until the line is full! All you have to do is either:
Thats it for today, ill post up another tut tomorrow about VARIABLES so you can learn to INPUT.Code:cout << "Line one" << endl; cout << "Line two"; OR cout << "Line one\nLine two"; OR cout << "Line one\n"; cout << "Line two";
Credits:
Juan Soulie
P0SEID0N
Last edited by P0SEID0N; 04-13-2010 at 06:30 PM.
[C]hosen-1 (04-13-2010)
Is this completely your guide?
I'm back.
hello,
im completely new to this. After I compiled and ran it, a window popped up saying sup bitches, but the window only remained for half a second and closed. it kept doing that when i kept running it again and again. is it supposed to be like that?
Goood job man.