Here’s some examples of how to use cout. This list is not exhaustive, and does not cover all use cases. This is just to give you an idea.

#include<iostream>

using namespace std;

//This is a function we'll talk about these in lesson 18 / 19
int returnNumber(){
	int number = 5 + 5;
	return number;
}


int main(){
	int myNumber = 5; // Declare a whole number variable (integer) and set it equal to 5
	cout << "Test" << endl; // Will Output Test, without quotation marks then skip to the next line
	cout << myNumber << endl; // Will output 5, and then go to the next line
	cout << "\nInline-line-break" <<endl; //This will output a blank line (\n) followed by the words Inline-Line-Break
	cout << "1+1=" << 1 + 1 << "\t2+2=" << 2 + 2 << endl; //Outputs "1+1=2" followed by a tab (\t) then "2+2=4" and then skips to the next line
	cout << returnNumber() << endl;  //This will output 10, then got to the next line (this is covered around lesson 18)

	system("PAUSE"); //This is a visual studio command which keeps the console window open until you press a button at the end.
	return 0;
}

Last modified: February 13, 2015

Author

Comments

Comments are closed.