What is the use of cout put () in C++?

To print a value to the screen, write the word cout, followed by the insertion operator (<<), which you create by typing the less-than character (<) twice. Even though this is two characters, C++ treats it as one.
Follow the insertion character with your data. Listing below illustrates how this is used. Type in the example exactly as written, except substitute your own name where you see Jesse Liberty (unless your name is Jesse Liberty, in which case leave it just the way it is; it's perfect-- but I'm still not splitting royalties!).
Listing : Using cout.

#include <iostream.h>
int main()
{
    cout << "Hello there.\n";
    cout << "Here is 5: " << 5 << "\n";
    cout << "The manipulator endl writes a new line to the screen." <<endl;
    cout << "Here is a very big number:\t" << 70000 << endl;
    cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;
    cout << "Here's a fraction:\t\t" << (float) 5/8 << endl;
    cout << "And a very very big number:\t" << (double) 7000 * 7000 <<endl;
    cout << "Don't forget to replace Jesse Liberty with your name...\n";
    cout << "Jesse Liberty is a C++ programmer!\n";
   
    return 0;
}

Output:
Hello there.
Here is 5: 5
The manipulator endl writes a new line to the screen.
Here is a very big number: 70000
Here is the sum of 8 and 5: 13
Atmiya Infotech
Here's a fraction: 0.625
And a very very big number: 4.9e+07
Don't forget to replace Jesse Liberty with your name...
Jesse Liberty is a C++ programmer!

Post a Comment

0 Comments