Answers for "c++ string to char array"

C++
9

string to char array c++

std::string myWord = "myWord";
char myArray[myWord.size()+1];//as 1 char space for null is also required
strcpy(myArray, myWord.c_str());
Posted by: Guest on August-27-2020
2

c++ string to char array

const char *array = tmp.c_str(); //For const char array
char *array = &tmp[0]; // If you need to modify the array
Posted by: Guest on September-28-2020
0

c++ string to char array

std::string strCoffee = "Nescafe";
const char *charCoffee = strCoffee.c_str();
Posted by: Guest on October-14-2021

Browse Popular Code Answers by Language