Q:

Read character array as string using cin in C++

0

Read character array as string using cin in C++

We have to character array known as string in C++ using "cin".

In this example, we reading firstName and secondName of a person and printing them.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#include <iostream>
using namespace std;

int main()
{
	char firstName[30], secondName[30];

	//input values
	cout<<"What is your first name? ";
	cin>>firstName;
	cout<<"What is your second name? ";
	cin>>secondName;

	//printing
	cout<<"Hi "<<firstName<<" "<<secondName<<endl;
	
	return 0;
}

Output

What is your first name? Amit
What is your second name? Shukla
Hi Amit Shukla

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to demonstrate example of cascading co... >>
<< C++ program to print Hello World/First Program in ...