Here We will Discuss how we will take multiline input. Previously we had performed it using cin and cout function but while using it will give us the output which is before the space so we will use get() fuction, It is an overloaded function which is used as get(char), get(char,count),get(char,count,deliminator)
/*How to take sentence from user*/
#include<iostream>
using namespace std;
int main(){
char name[20];
cout<< "Enter Your Full Name:";
cin.get(name,20); //get(char),get(char*,Count),get(char*,count,delim)
cout<<"Welcome"<<name;
return 0;}
If we wish to take full paragraph then we have to do it as follows:
/*How to take sentence from user*/
#include<iostream>
using namespace std;
int main(){
char name[200];
cout<< "Enter any paragraph(enter $ for the finish): ";
cin.get(name,200,'$');
cout<<"You had written"<<endl<<name;
return 0;}
/*Write program to take your fullname, email id, contact address in a single variable with new line character embedded in text and display it*/
#include<iostream>
using namespace std;
int main(){
char info[100];
cout<<"Enter your Detail";
cin.get(info,100,'$');
cout<<"Your Detail is"<<endl;
cout<<info;
return 0;}
0 Comments had been done yet:
Post a Comment