6. Write a C++ to illustrate the concepts of console I/O operations.

#include <iostream>

#include<conio.h>

using namespace std;

int main() {

 char c;

 cout<<"\nEnter any character value: ";

 c=cin.get();

 cout.put(c); //Here it prints the value of variable c;

 cout.put('c'); //Here it prints the character 'c';

return 0;

}

Output:




#include <iostream>
#include<conio.h>
using namespace std;
int main() {
 cout<<"\nEnter any name : ";
 char c[10];
 cin.getline(c,10); //It takes 10 charcters as input;
 cout.write(c,9); //It reads only 9 character from buffer c;
 cout<<"\n";
return 0;
}

Output:

#include <iostream>
#include<conio.h>
using namespace std;
int main() {
 int num;
 char ch;
 string str;
 cout<<"\nEnter Number: ";
 cin>>num; //Inputs a variable;
 cout<<"Enter Character: ";
 cin>>ch; //Inputs a character;
 cout<<"Enter String: ";
 cin>>str; //Inputs a string;
 cout<<endl <<"You have entered:\nNumber: "<<num<<"\nCharacter: "
 <<ch<<"\nString: "<<str<<endl;
 return 0;
}
 Output: