Results 1 to 3 of 3
  1. #1
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking

    Learn how to code C++ || Day 2 - Basic Output

    Lesson #2 - Basic Output

    Today we are going to be looking at the acts of output.

    Quote Originally Posted by Juan Soulie View Post
    C++ uses a convenient abstraction called streams to perform input and output operations in sequential media such as the screen or the keyboard. A stream is an object where a program can either insert or extract characters to/from it.
    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):

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
     cout << "Sup bitches";
     return 0;
    }
    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.

    [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:

    Code:
    cout << "Line one" << endl;
    cout << "Line two";
    
    OR
    
    cout << "Line one\nLine two";
    
    OR
    
    cout << "Line one\n";
    cout << "Line two";
    Thats it for today, ill post up another tut tomorrow about VARIABLES so you can learn to INPUT.

    Credits:
    Juan Soulie
    P0SEID0N
    Last edited by P0SEID0N; 04-13-2010 at 06:27 PM.

  2. The Following 2 Users Say Thank You to P0SEID0N For This Useful Post:

    skykrutch (04-14-2010),TheOfficialC7 (04-13-2014)

  3. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Nice job and good explanation.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  4. #3
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking
    Thanks I did my best, it's actually harder than i though trying to explain some things, like i know what it is in my head, i just cant put it into words.

Similar Threads

  1. Learn how to code C++ || Day 3 - Variables and Date Types
    By P0SEID0N in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 8
    Last Post: 04-16-2010, 09:26 PM
  2. Learn how to code C++ || Day 3 - Variables and Date Types
    By P0SEID0N in forum C++/C Programming
    Replies: 5
    Last Post: 04-16-2010, 02:51 AM
  3. Learn how to code C++ || Day 2 - Basic Output
    By P0SEID0N in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 5
    Last Post: 04-15-2010, 04:00 AM
  4. Learn how to code C++ || Day 1 - Compiler
    By P0SEID0N in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 14
    Last Post: 04-15-2010, 02:42 AM
  5. Learn how to code C++ || Day 1 - Compiler
    By P0SEID0N in forum C++/C Programming
    Replies: 5
    Last Post: 04-13-2010, 06:21 PM