Console Output in C++
September 13, 2010 Leave a Comment
The command used for outputting text to console is the ‘cout’ statement. It resides in the iostream.h header file within the std namespace. For now ignore the terms and just get familiar with the program below.
Here is a simple program that outputs data to the console.
#include <iostream>
using namespace std;int main() {
// cout is an output stream, that represents the standart output stream
// “<<” operator is known as “insertion operator”
// is outputs data to the stream
cout << ”A string”;
// to insert a newline, output manipulator endl
cout << endl;
// or one can combine those two outputs in one line of code
cout << ”Another string” << endl;
// one can output a number in a similar way
cout << ”Number: “ << 7 << endl;
int data = 9;
cout << “The data variable contains the value: ” << data << endl;
return 0;
}
Output of the Above Program would be
A string
Another string
Number: 7
The data variable contains the value 9
Recent Comments