Insertion (<<) and extraction (>>) operators C++ program 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: Using the C++ operator << and >> to insert a string to the output stream and extracts a string from the input stream in C++ programming
To show: How to use the C++ << and >> operators to insert a string to the output stream and extracts a string from the input stream in C++ programming
// the C++ << and >> operators program example
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
string Sample = "Testing the <<and>> operators.";
string Var1, Var2;
cout<<Sample<<endl;
cout<<"Enter a string or a word: ";
cin>>Var1;
cout<<"Enter another string or a word: ";
cin>>Var2;
cout<<"The strings entered are: "<<Var1<<" and "<<Var2<<endl;
return 0;
}
Output example:
Testing the << and >> operators.
Enter a string or a word: simple
Enter another string or a word: string
The strings entered are: simple and string
Enter two strings: more string
Another string: more string
Press any key to continue . . .