[SOLVED] Converting String to Cstring in C++

Issue

I have a string to convert, string = "apple" and want to put that into a C string of this style, char *c, that holds {a, p, p, l, e, '\0'}. Which predefined method should I be using?

Solution

.c_str() returns a const char*. If you need a mutable version, you will need to produce a copy yourself.

Answered By – Yann Ramin

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *