Answers for "how to assign a string to a char array in 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
3

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

Code answers related to "how to assign a string to a char array in c++"

Browse Popular Code Answers by Language