It won't automatically convert (thank god). You'll have to use the method c_str() to get the C string version.

std::string str = "string";
const char *cstr = str.c_str();

.c_str() returns a const char *. If you want a non-const char *, use .data():

std::string str = "string";
char *cstr = str.data();

Some other options:

  • Copying the characters into a vector:

    std::vector<char> cstr(str.c_str(), str.c_str() + str.size() + 1);
    

    Then cstr.data() will give you the pointer.

    This version copies the terminating \0. If you don't want it, remove + 1 or do std::vector<char> cstr(str.begin(), str.end());.

  • Copying into a manually allocated array: (should normally be avoided, as manual memory management is easy to get wrong)

    std::string str = "string";
    char *cstr = new char[str.size() + 1];
    std::strcpy(cstr, str.c_str());
    // do stuff
    delete [] cstr;
    
Answer from orlp on Stack Overflow
Discussions

How to convert a string to character array in c (or) how to extract a single char form string? - Stack Overflow
I need to convert a string to a char array in C; how can I do this? Or at least, how can I extract single chars from a string incrementally? More on stackoverflow.com
🌐 stackoverflow.com
String to char* conversion
Hi all, I am trying to convert a string to char*. I use the Serial.println function to examine the values inside the pointer and the first character is unknown (as in inverted ?). The serial monitor shows temp: 1010, lo… More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
November 7, 2018
How do I convert a string to an array of chars in C?
No need. string[n] IS char[n] of string. If you try to print string[n] as a char (instead of a string) you'll get that letter. You can evaluate and modify it just like that. No fuss, no muss. (For fun: You can also printf, say, char[5] of a string as a string, and it'll print everything from that letter on.) Note that the array is zero indexed, and there's an invisible null on the end of that string that doesn't get measured. So "Hello!" will return a length of 6, but is an array of char[7]. The extra char (7) holds the null. More info: Yes, a string is just an array of char. When functions like printf are told to print a string, they go to the supplied variable's address and keep printing (or otherwise acting on) the char found there until they hit a null (\0). (This is why printing a string you've manipulated can segfault.) This is ALSO why in higher level languages that allow strings to be concatenated it's considered an "expensive" thing to do - because you can't just append to the end of an array, you need to make a new one and copy everything over. More on reddit.com
🌐 r/cs50
6
3
March 21, 2023
Simplest way to convert characters into a string? (C)
There are some details about strings and character arrays in C that trip up new programmers. CS50 attempts to 'paper over' some of these with the 'string' data type. In a few weeks the lectures will reveal the inner workings of 'string' and show you how to work without it. If you change to char key[6] = "abcde"; that will declare and fill in a character array. Then you could, inside your loop, replace individual characters with their uppercase twins: key[i] = toupper(key[i]); and then use printf to print the entire string: printf("%s", key); If that doesn't make sense, it will soon once they strip away 'string' and show you how character arrays and strings 'really' work. More on reddit.com
🌐 r/cs50
5
1
May 2, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-convert-a-string-to-a-char-array-in-c
How to Convert a String to a Char Array in C? - GeeksforGeeks
July 23, 2025 - The most straightforward method to convert a string to a char array is by using strcpy() function.
🌐
Quora
quora.com › How-do-I-convert-a-char-to-string-in-C
How to convert a char to string in C - Quora
Answer (1 of 6): C is a procedure oriented language. Unlike C++ it does not have any string object support or java that has string as a primitive data type. In C string is simply an array of characters but the only condition is that it must be terminated by a null character,i.e '\0’. To convert...
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
Since strings are actually arrays in C, you can access a string by referring to its index number inside square brackets []. This example prints the first character (0) in greetings:
🌐
DigitalOcean
digitalocean.com › community › tutorials › convert-string-to-char-array-c-plus-plus
Convert String to Char Array and Char Array to String in C++ | DigitalOcean
August 3, 2022 - C++ c_str() function along with C++ String strcpy() function can be used to convert a string to char array easily.
Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › projects › programming
String to char* conversion - Programming - Arduino Forum
November 7, 2018 - Hi all, I am trying to convert a string to char*. I use the Serial.println function to examine the values inside the pointer and the first character is unknown (as in inverted ?). The serial monitor shows temp: 1010, lookUpvar:?010. Anyone knows why? void loop(){ String temp = "1010"; char* lookup_var; Serial.print("temp:");Serial.println (temp); strcpy(lookup_var, temp.c_str()); Serial.print("lookUpvar:");Serial.println (lookup_var); }
🌐
Quora
quora.com › What-are-the-steps-to-convert-String-to-Char-Array-in-C
What are the steps to convert String to Char Array in C? - Quora
Answer (1 of 12): As the answers say, a string is a char array, mostly. This answer is a bit wrong in some contexts. I am thinking of string constants specifically. A string constant should probably not be treated as a char array in terms of modifying it. If I say char *p = “string constant”; ...
🌐
Reddit
reddit.com › r/cs50 › how do i convert a string to an array of chars in c?
r/cs50 on Reddit: How do I convert a string to an array of chars in C?
March 21, 2023 -

I know that a string is already technically an array of chars, but when I try to use toupper(string), it doesn’t work because toupper is designed to capitalize chars and not strings, per the documentation. I’ve been making it overly complicated and it’s stressing me out. So to start, I created an “int N=strlen(string);”, then created an array that’s “char upper[N];”. Then I write a for loop written as(please forgive the terrible syntax I’m about to write), “for (int i = 0; i < N; i++) { toupper(upper[j]); }”. What am I doing wrong?

🌐
Swarthmore College
cs.swarthmore.edu › ~newhall › unixhelp › C_strings.html
C library functions for strings (string.h)
C string library functions do not allocate space for the strings they manipulate, nor do they check that you pass in valid strings; it is up to your program to allocate space for the strings that the C string library will use. Calling string library functions with bad address values will cause a segfault or "strange" memory access errors. Here is a description of some of the functions in the Stardard C string libarary (string.h) for manipulating strings: #include <string.h> int strlen(char *s); // returns the length of the string // not including the null character char *strcpy(char *dst, char
🌐
Reddit
reddit.com › r/cs50 › simplest way to convert characters into a string? (c)
r/cs50 on Reddit: Simplest way to convert characters into a string? (C)
May 2, 2020 -

Hello everyone!

In this simple example, how can I replace the new_key string contents with the uppercase of the key string? I can print it alright with the below code, but can't find a way to store the characters in the empty string - there are always either segmentation fault errors or initializer ones.

What would be the best way to make new_key[i] be the content of toupper(key[i])?

#include <stdio.h>

#include <cs50.h>

#include <string.h>

#include <stdlib.h>

#include <ctype.h>

int main(void)

{

string key = "abcde";

string new_key[] = "";

for (int i = 0, len = strlen(key); i < len; i++)

{

char c = key[i];

printf("%c", toupper(c));

}

}

🌐
Cplusplus
cplusplus.com › forum › beginner › 202674
Convert single character string to char - C++ Forum
November 17, 2016 - I'm trying to convert a single character string into a char. I would rather not have to use an array to try to keep the code simpler. Is there a method for changing the string into an array or do I just need to use a char array regardless?
🌐
Reddit
reddit.com › r/cprogramming › why does char* create a string?
r/cprogramming on Reddit: Why does char* create a string?
June 18, 2025 -

I've run into a lot of pointer related stuff recently, since then, one thing came up to my mind: "why does char* represent a string?"

and after this unsolved question, which i treated like some kind of axiom, I've ran into a new one, char**, the way I'm dealing with it feels like the same as dealing with an array of strings, and now I'm really curious about it

So, what's happening?

EDIT: i know strings doesn't exist in C and are represented by an array of char

🌐
GeeksforGeeks
geeksforgeeks.org › c++ › convert-char-to-string-in-cpp
Convert char* to std::string in C++ - GeeksforGeeks
July 23, 2025 - In C++, the easiest method to convert char* (C-style string) to a std::string is by simply assigning it to the std::string object using (=) assignment operator.
🌐
Medium
medium.com › @muirujackson › char-pointer-to-string-in-c-aa4b59fdf289
Declaration of String in C. In C, char [] and char * are both used… | by Muiru Jackson | Medium
April 6, 2023 - So in the code char* str = "Hello";, the string literal "Hello" is automatically converted to a character array of size 6 (5 characters for the string and 1 null character) and the memory address of the first character 'H' is assigned to the ...