Summary: In this programming tutorial, we will learn to convert a char array into a string in C++.


There are different methods to convert an array of characters into a single string value in C++. Let’s look at some methods with examples:

Method 1: Using ‘=’ Operator

Each character in a string or char array has an index value. We can easily assign every character to their respective index position in string by using the assignment (=) in C++.

Note: Use the cin.getline() method for taking input into char array or else the elements after space will be eliminated.

Method 2: Using String Constructor

The string constructor accepts a char array as a parameter, which is then converted to a string value.

Output of both programs will be the same:

char array to string in C++ output

These are the two ways using which we can convert an array of characters into a string value in the C++ programming language.

Leave a Reply

15 − thirteen =