+ 1

[SOLVED] What is the most easiest way to convert string to char array and vice-versa? In C++

23rd Nov 2019, 4:45 PM
Nailsonseat
Nailsonseat - avatar
3 Answers
+ 7
Well a string object can be used as a char array std::string name = "Jackson"; std::cout << name[0]; // J std::cout << name[1]; // a but if you really want a char array -allocate memory for a char array + null terminator. -copy its contents using a loop. For less code use strcpy(charArray, name.c_str());
23rd Nov 2019, 5:00 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
Nailsonseat Youre welcome It was not dumb at all; we all start somewhere :) If people didnt ask even the dumbest of questions we wouldnt be as advanced as we are now
23rd Nov 2019, 6:54 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 1
Thank you very much, it was a dumb question. I'm a noob at this
23rd Nov 2019, 5:08 PM
Nailsonseat
Nailsonseat - avatar