Learn More

Wednesday, October 12, 2011

Basic Input Output In C++

c++ logo
In the previous topic about c++, we have learned about the operator. In that example, you see cout and iostream. Those parts are the basic input and output in c++. And this time we learn the basics of input and output.

Iostream is the definition of input and output stream. When we include the iostream library, then we can do input and output of a program.



cout

This command produces output of a program on the screen. cout is always associated with an insertion operator, <<, with operator of this the data that follows thereafter will be processed. You can enter the operator more than once, consider the following example


To note when we use the cout, that the result of court does not produce a new line. So our suggestion to add the code with the endl, consider the following example




cin

This operator is the opposite of the service cout. This operator serves as the input of a program (via keyboard). And every cin always followed by the extraction operator, >>, you need to consider is the type of variables used. If you use double then cin will read it as a double variable.


As with any cout, extraction operators can also be inserted more than one.


above code would require two inputs with variable names are a and b. We can also use cin to input a string. However, when the string is a sentence, then cin can not read it properly. Therefore, the use of getline is very good. Please note, if you use the input string, then you must add the string library.

  1. waww keren banget blog nya... mau nanya ni gimana cara bikin panel label seperti yang di bagian bawa halaman blog anda..

    ReplyDelete
  2. Untuk mas braja, terima kasih penilaiannya, untuk bagaimana cara membuat sebuah panel label seperti bagian bawah blog kami, anda bisa mempelajarinya melalui tutorial kami multi label recent post, adapun untuk multi label recent post dengan thumbnail seperti milik kami akan kami perjelas bila anda menjadi member dari blog ini.

    ReplyDelete
  3. wahhh sip lah...
    ..untuk jadi member cukup dengan follow aja kan bang..

    ok kalo gitu ku akan segera merapat sayang.. :D canda

    ReplyDelete
  4. There is "cerr << xxx" that is rarely used. Instead of writing to standard output (stdout) as done by "cout << xxx", it writes to standard error (stderr). Very useful when you write a program that needs to separate normal output and error message.

    ReplyDelete
    Replies
    1. For Muhammad Alvin:
      Once again, thank you for your share. In this post, we explain how to use cout and cin. And those must doing by us. Because it's for help others to learn c++ from basic until expert. We know someone need more. But we have a limit for time. So what we hope from others with this blog is as a place for share.

      Delete