There are different ways to convert char * to string in C++.

Before proceding I recommend you to have a look on how to convert char array to string in C++?

Since char * and char array are almost similar so char pointer can be easily converted to string in the same manner.

Char * to String C++ using ‘=’ Operator

Since each character in the string has index value, so by using = operator we can directly assign each character in the char pointer to its corresponding index in the string variable.

Output

Char * to String in C++ using String Constructor

Inbuilt string constructor of string class accepts char pointer array as argument which implicitly converts and assigns it to the string variable.

Output

comment below if you know more techniques to convert char * to string in C++, I will add to the post.

Close Menu