How to convert string to char?
There is an arbitrary string of no more than 25 characters. For example "wo1fram"
How do I convert it to a char[255] array?
So that you can then work with char as a full-fledged array of characters ending in a null character.
1 answers
Here, you see, there are two solutions.
One thing - if you only need to read this line, or there, change a couple of characters in it - but not change its size (so that all strcpy
are canceled) - then you can use the functions c_str()
and data()
. I highly recommend that you carefully read the descriptions, and most importantly-the restrictions imposed by these functions.
And another thing - if you need to work with it as a string in the C style with all the features, then just copy it to array, type
char buf[255];
strcpy(buf,s.c_str());
Or
char * buf = strdup(s);
Something like that.