--Originally published at TC1017 Solving Problems with Programming
Hi there! Today I have a new topic for you. When you are making a program code everything you write will not appear in the screen unless you print it. This is an output.And the input is something that you will receive from the user of the program.
This is how you use the output or cout
|
|
The <<
operator inserts the data that follows it into the stream that precedes it. In the examples above, it inserted the literal string Output sentence
, the number 120
, and the value of variable x
into the standard output stream cout
. Notice that the sentence in the first statement is enclosed in double quotes ("
) because it is a string literal, while in the last one, x
is not. The double quoting is what makes the difference; when the text is enclosed between them, the text is printed literally; when they are not, the text is interpreted as the identifier of a variable, and its value is printed instead. For example, these two sentences have very different results:
|
|
And this is how you use the input or cin
For formatted input operations, cin
is used together with the extraction operator, which is written as >>
(i.e., two “greater than” signs). This operator is then followed by the variable where the extracted data is stored. For example:
|
|
The first statement declares a variable of type int
called
Continue reading "Input and Output"