Follow Us

LightBlog

Breaking

Sunday, May 31, 2020

Input and Output

C++ Basic Input/Output
 
In this tutorial, we will learn to use the cin object to take input from the user, and the cout object to display output to the user with the help of examples.
cin:  cin object to take input from the user.
cout: cout object to display output to the user.
Example 1: String Output.
#include <iostream>
using namespace std;
int main() 
{
    cout << "This is C++ Programming";
    return 0;
}
OutPut: This is C++ Programming.
Hints: prints the string enclosed in double-quotes.
Example 2: Numbers and Characters Output.
#include <iostream>
using namespace std;
int main() 
{
    int number1 = 50;
    double number2 = 256.783;
    char ch = 'B';
    cout << number1 << endl;    // print integer
    cout << number2 << endl;    // print double
    cout << "character: " << ch << endl;    // print char
    return 0;
}
OutPut: 
50
256.783
character: B



No comments:

Post a Comment