C++ program to take input in string format with whitespaces
In this chapter of CPP program tutorial, our task is to :
-
write a cpp program to take input in string format with whitespaces
CPP program to take input in string format with whitespaces.
Given below is the cpp program to take input in string format with whitespaces
/* Program Name : CPP program to take input in string format with whitespaces.
Program Author : Krushna Kulkarni
*/
#include<iostream>
#include<string> //for string class
using namespace std;
int main(){
//declaring string variable
string s;
//using getline() function to read string input "Tutorials In Hand"
getline(s, cin);
//printing the output string
cout<< s <<endl;
return 0;
}
INPUT
Tutorials In Hand
OUTPUT
Tutorials In Hand
EXPLANATION :
In the above cpp program to take input in string format with whitespace:
You can see the above code execution and output in codechef IDE:
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Page Views :
Published Date :
Mar 11,2021