Home » C++ programs » C++ basic programs

Read character array as string using cin in C++

Here, we are implementing a program in which we are reading a character array using cin in C++.
Submitted by IncludeHelp, on November 02, 2018

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.