Concatenating lateral string using the C++ redirection operator, << code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Concatenating lateral string using the C++ redirection operator, << in C++ programming

To show: How to concatenate lateral string using the C++ redirection operator, << in C++ programming

 

// concatenating using the << operator

#include <iostream>

using namespace std;

 

void main(void)

{

int p = 3, q = 10;

 

cout << "Concatenating using << operator.\n"

<<"--------------------------------"<<endl;

cout << "70 minus 20 is "<<(70 - 20)<<endl;

cout << "55 plus 4 is "<<(55 + 4)<<endl;

cout <<p<<" + "<<q<<" = "<<(p+q)<<endl;

return;

}

 

Output example:

 

Concatenating using << operator.

--------------------------------

70 minus 20 is 50

55 plus 4 is 59

3 + 10 = 13

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index