Saturday, 3 February 2018

C++ Basic Input/Output

iostream
It stands for input output stream(input stream +output stream).

Stream is the flow of data.Data will flow from input to output and it makes the performance faster

It is used to define the cout, cin and cerr objects, which correspond to standard output stream, standard input stream and standard error stream respectively.


Standard output stream(cout)
cout is a predefined object of ostream class.
It is used to display or print the output.
It is denoted by stream insertion operator (<<) to display the output on a console

Example:

#include <iostream> 
using namespace std; 
int main() { 
   char name[] = " LearningPoint92"; 
   cout << "Welcome to " << name << endl; 
   return 0;

OR

#include <iostream.h> 
#include<conio.h>
void main() { 
   char name[] = " LearningPoint92"; 
 clrscr();
   cout << "Welcome to " << name << endl; 
 getch();


Output:
Welcome to LearningPoint92


Standard input stream(cin)

 cin is a predefined object of istream class.
 It is used to take value from user(using keyword).
 It is denoted  by stream extraction operator (>>) to read the input from a console

Example:
#include <iostream.h> 
 #include<conio.h>
void main() { 
  char name[20]; 
clrscr();
   cout << "Enter your name: "; 
   cin >> name; 
   cout << " Name is: " << name<< endl; 
getch();
Output:
Enter your name:
Dev
Name is Dev


Standard end line(endl)
 endl is a predefined object of ostream class.
 It is used to insert a new line characters.

Example:
#include <iostream.h> 
 #include<conio.h>
void main() { 
  char name[20]; 
  int age;
 clrscr();
   cout << "Enter your name: "<<endl;
   cin >> name; 
   cout << " Name is: " << name<< endl; 
cout << "Enter your age: "<<endl; 
   cin >> age; 
   cout << " Age is: " << age<< endl; 
getch();
Output:
Enter your name:
Dev
Enter your age:
25
Name is Dev
Age is 25


No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...