Friday, February 16, 2024

C++ INPUT/OUTPUT

 C++ input/output

  • ABOUT C-IN/C-OUT


Cin Cout

CIN (the standard input stream)

The predefined object cin is an instance of the istream class. The cin object is said to be attached to a standard input device, usually a keyboard. Cin is used in conjunction with the stream extraction operator, written as >> which are two larger signs, as in the following example.

#include <iostream>
 
using namespace std;
 
int main() {
   char name[50];
 
   cout << "Please enter your name: ";
   cin >> name;
   cout << "Your name is: " << name << endl;
 
}

The C++ compiler also determines the data type of the entered value and selects the appropriate stream extraction operator to extract the value and store it in the given variables.

The stream extraction operator >> may be used more than once in a single statement. To request more than one datum you can use the following

cin >> name >> age;

This will be equivalent to the following two statements –

 

cin >> name;

cin >> age;

C-out (the standard output stream)

The predefined c-out object is an instance of the ostream class. The c-out object is said to be "connected" to a standard output device, usually a display screen.

Cost is used in conjunction with the stream insertion operator, << which are two smaller signs, as in the following example.

#include <iostream>

using namespace std;
int main() {
   char str[] = "Hello C++";
   cout << "Value of str is : " << str << endl;
}

Output

Hello C++

The C++ compiler also determines the data type of the variable to create and selects the appropriate stream insertion operator to display the value. << Operators are overloaded to create data elements of integer, float, multiplier, string, and pointer value types.

Insertion operator << can be used multiple times in a single statement as shown above and endl is used to add a newline at the end of a line

No comments:

Post a Comment

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular