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

Answer from Yann Ramin on Stack Overflow
Discussions

converting c style string to c++ style string - Stack Overflow
Can anyone please tell me how to convert a C style string (i.e a char* ) to a c++ style string (i.e. std::string) in a C++ program? Thanks a lot. More on stackoverflow.com
๐ŸŒ stackoverflow.com
arduino ide - Convert C string to C++ string - Arduino Stack Exchange
My program is running on ESP32. I'm retrieving some data from Bluetooth, and the Bluetooth string is a C string. I need to save that data in an RTC_DATA_ATTR String, which is a C++ string. Just do... More on arduino.stackexchange.com
๐ŸŒ arduino.stackexchange.com
November 21, 2020
C++ experts - implicit conversion of String to C-string?
The String class has the c_str() method to convert to a const char*. However, this means we have lots of duplicated APIs in the code, e.g. void Spark.subscribe(const char* eventName, ...); and void Spark.subscribe(String eventName, ...) { Spark.subscribe(eventName.c_str(), ...); } With the ... More on community.particle.io
๐ŸŒ community.particle.io
0
4
April 24, 2015
c++ - Using c.str to convert from string to cstring - Stack Overflow
I am practicing some work with cstring and string. Going from string to cstring using c_str() I get an incompatible data type compile error. For example this is the code that gives said error: str... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Stack Exchange
arduino.stackexchange.com โ€บ questions โ€บ 71384 โ€บ convert-c-string-to-c-string
arduino ide - Convert C string to C++ string - Arduino Stack Exchange
November 21, 2020 - Just doing c++string = cstring.c_str(); won't work, since it will just save a pointer to the location in the memory of the C string, and the purpose is to save the data in the RTC memory, so the ESP32 can go to deep sleep without losing the data.
๐ŸŒ
Particle
community.particle.io โ€บ firmware
C++ experts - implicit conversion of String to C-string? - Firmware - Particle
April 24, 2015 - The String class has the c_str() ...cribe(eventName.c_str(), ...); } With the String api simply unwrapping the string to a C-string and calling the C-string function....
๐ŸŒ
Bham
epweb2.ph.bham.ac.uk โ€บ user โ€บ hillier โ€บ course3cpp โ€บ howto โ€บ cstrings.html
Converting data to C++ and C-style strings
The most general way of making a C-string from anything that can be output with the << insertion operator is to use a function like this (shorter solutions welcomed): #include <sstream> // Convert to C-string.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-an-std-string-to-a-C-string-in-C
How to convert an std::string to a C string in C++ - Quora
Answer (1 of 7): All other answers only mention std::string::c_str() but there is also an accessor for the non-const pointer to the underlying string: std::basic_string::data - cppreference.com Since C++11 it has the same behavior as c_str() except for the const qualifier. It explicitly allows ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ answers โ€บ questions โ€บ 493091 โ€บ how-to-convert-cstring-to-string-without-loosing-a
How to convert CString to string without loosing any characters - Microsoft Q&A
Your subject mentions null characters, which implies that your string has several null separated strings, though you fail to mention that in the question, so I'm wondering whether that is the case or not? Clarify your question with some specific details so that someone can give you a more informed answer. ... It is not clear what kind of CString do you have (CStringA or CStringW). If it is a CStringW, it can be converted to char* or CStringA strings using UTF-8 encoding and WideCharToMultiByte function (assuming that the source string is valid).
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
I Want to Convert a std::string to a cstring - Programming - Arduino Forum
January 28, 2020 - Hi all, I want to convert a std::string to a cstring. I have found this tutorial but it is for converting a std::string to a "const char" not a "char": So how do I convert a std::string to a cstring? Thanks very mucโ€ฆ
๐ŸŒ
Tomeko
tomeko.net โ€บ online_tools โ€บ cpp_text_escape.php
Text -> C/C++ string converter
Converting text into C-like literal, escaping newlines, tab, double quotes, backslash.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-convert-c-style-strings-to-stdstring-and-vice-versa
How to convert C style strings to std::string and vice versa? - GeeksforGeeks
July 6, 2017 - They are easy to operate. โ€˜+โ€™ operator for concatenation, '=' for assignment, can be compared using regular operators. string::find() and many other functions can be implemented on std::string and not on C-Strings so this becomes handy.
๐ŸŒ
Experts Exchange
experts-exchange.com โ€บ questions โ€บ 28817659 โ€บ Convert-CString-to-String-C.html
Solved: Convert CString to String C++ | Experts Exchange
November 6, 2015 - Please rename the .txt file to .vcxproj Thanks, Karrtik ยท CString somename = L"This string is somename.";//This is a unicode string since in project settings we have set character set as use unicode character set --> General settings //Test case1: Convert unicode CString to standard C++ string std::wstring ws(somename);//wstring is the unicode couterpart of std::string in C++ standard library and since CString is containing unicode, it can be directly assigned to ws.
๐ŸŒ
Cplusplus
cplusplus.com โ€บ forum โ€บ beginner โ€บ 120021
C++ string to Cstring - C++ Forum
Uh not sure why you would want to do that manually, but you could always use operator[] which std::string implements. http://www.cplusplus.com/reference/string/string/operator[]/ Just iterate through, pulling out each character and assigning it to a C-style string.
๐ŸŒ
Quora
quora.com โ€บ How-does-one-convert-from-string-to-c_string-Could-somebody-give-me-an-example
How does one convert from string to c_string? Could somebody give me an example? - Quora
Answer (1 of 2): The [code ]c_str() [/code]member function return a [code ]const char*[/code] to the string internal buffer, that is granted to be null terminated at least upon its call (c++98) or always (c++11). You will not own the string data through that pointer, but -as far as the std::stri...