+ 1
[SOLVED] What is the most easiest way to convert string to char array and vice-versa? In C++
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());
+ 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
+ 1
Thank you very much, it was a dumb question. I'm a noob at this