How to Convert a std::string to char* in C++? Last Updated : 14 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "GeeksforGeeks";Convert std::string to char* in C++The std::string is also implemented using char array so it is very easy and straightforward to perform this conversion. To convert a std::string to a char*, we can use the std::string:c_str() method that returns a pointer to a null-terminated character array (a C-style string). C++ Program to Convert std::string to char* C++ // C++ program to convert string to char* #include <iostream> #include <string> using namespace std; int main() { // declaring string string myString = "Geeks For Geeks"; cout << "string: " << myString << endl; // Using c_str() to get a pointer to a null-terminated // character array const char* charPointer = myString.c_str(); // Now you can use charPointer as a regular C-style // string cout << "C-style string: " << charPointer << endl; return 0; } Outputstring: Geeks For Geeks C-style string: Geeks For Geeks Time Complexity: O(1)Space Complexity: O(1) Comment More infoAdvertise with us Next Article How to Convert a std::string to char* in C++? M m0hitkirange Follow Improve Article Tags : C++ Programs C++ STL cpp-string CPP Examples +1 More Practice Tags : CPPSTL Similar Reads Convert char* to std::string in C++ Strings are generally represented as an instance of std::string class in C++. But the language also supports the older C-Style representation where they are represented as array of characters (char* or char[]) terminated by null character '\0'. In this article, we will learn how to convert the char* 3 min read How to Convert a Single Character to String in C++? A string is a generally made up of a sequence of multiple characters. In this article, we will learn how to convert a single character to a string in C++.Example:Input: c = 'A'Output: s = "a"Explanation: Character c is converted to a string.Input: c = '#'Output: s = "#"Explanation: Character c is co 4 min read How to Convert Char Array to Int in C++ In C++, a character array is treated as a sequence of characters also known as a string. Converting a character array into an integer is a common task that can be performed using various methods and in this article, we will learn how to convert char array to int in C++. Example Input:char arr1[] ="1 2 min read How to Convert std::string to Lower Case? Converting string to lower case means all the alphabets present in the string should be in lower case. In this article, we will learn how to convert the std::string to lowercase in C++.Examples Input: s = "GEEKS for GEEKS"Output: geeks for geeksExplanation: All characters of s are converted to lower 3 min read Convert String to Char Array in C++ In C++, we usually represent text data using the std::string object. But in some cases, we may need to convert a std::string to a character array, the traditional C-style strings. In this article, we will learn how to convert the string to char array in C++.ExamplesInput: str = "geeksforgeeks"Output 4 min read Like