// "std::string" has a method called "c_str()" that returns a "const char*"
// pointer to its inner memory. You can copy that "const char*" to a variable
// using "strcpy()".
std::string str = "Hello World";
char buffer[50];
strcpy(buffer, str.c_str());
std::cout << buffer; //Output: Hello World
//POSTED BY eferion ON STACK OVERFLOW (IN SPANISH).
// example
char sczName[] = {"Jakes"};
std::string strName = std::string(sczName);
/* SYNTAX
#include <string>
std::string(<char-to-convert>)
*/
std::string str = "string";
const char *cstr = str.c_str();
std::string str = "string";
const char *cstr = str.c_str();
std::cout << std::string(1, c) << std::endl;
char *cStr = "C++";
std::string Str = std::string(cStr);
std::string str = "string";
const char *cstr = str.c_str();
std::string str = "string";
const char *cstr = str.c_str();
std::string str = "string";
const char *cstr = str.c_str();
std::string str = "string";
const char *cstr = str.c_str();
assert(string.size() == 1);
char character = string[0];
std::string str = "string";
const char *cstr = str.c_str();
Code Example |
---|
Cpp :: minimum characters to make string palindrome |
Cpp :: c++ pointers and arrays |
Cpp :: new in c++ |
Cpp :: the difference between i++ and ++i |
Cpp :: c++ function pointer as variable |
Cpp :: c++ else if |
Cpp :: minimum or maximum in array c++ |
Cpp :: ex: cpp |
Cpp :: converting int to string c++ |
Cpp :: c++ last element of array |
Cpp :: long long vs long long int |
Cpp :: sort 2d vector c++ |
Cpp :: ? c++ |
Cpp :: double plus overload |
Cpp :: C/C++ loop for |
Cpp :: c++ void poiinter |
Cpp :: even or odd program in c++ |
Cpp :: faster solutions |
Cpp :: how to use printf with <cinttypes c++ |
Cpp :: binary to int c++ bitset |
Cpp :: c++ optimize big int array |
Cpp :: sfml thread multi argument function |
Cpp :: long, long long 32 bit or 8 bit in c++ |
Cpp :: sort vector in descending order c++ |
Cpp :: find with hash set |
Cpp :: Print value of data in c++ |
Cpp :: vermífugo significado |
Cpp :: Corong_ExerciseNo3(1) |
Cpp :: set precision on floating numbers |
Cpp :: determining a string is subsequence of another |