Answers for "how to change a char array c++"

C++
12

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
1

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