In this quick article, we’ll explore how to convert a C-string to std::string in C++.

1. Using string constructor

Download  Run Code

2. Using std::string::append function

Download  Run Code

3. Using std::string::assign function

Download  Run Code

4. Using + operator

Download  Run Code

 
It is worth noting that all the above solutions will error out if char* is NULL.

That’s all about converting a C-string to std::string in C++.