character array to string c++ stl

Converting a character array to a string using C++ STL

To convert a character array to a string using C++ STL, you can use the std::string constructor that takes a const char* parameter. Here are the steps:

  1. Create a character array.
  2. Use the std::string constructor to convert the character array to a string.

Here's an example:

#include <iostream>
#include <string>

int main() {
    const char charArray[] = "Hello, World!";
    std::string str(charArray);
    std::cout << "String: " << str << std::endl;
    return 0;
}

In this example, the const char* parameter of the std::string constructor is used to convert the character array charArray to a string str.