-
strings to arrays
How do you convert a string to an array of chars? Do you have to cast it,
or is there a function that will do it?
-
Re: strings to arrays
what do you mean? a std::string can be converted to char * by calling
the c_str() member function:
std::string s="hello";
const char * p = s.c_str();
cout<< p[0]; // displays 'h'
Danny
kingNewbie wrote:
>
> How do you convert a string to an array of chars? Do you have to cast it,
> or is there a function that will do it?
-
Re: strings to arrays
if you are using a character array to construct your string then by definition
your string is already an array.
int i;
char str[6] ="Hello";//always leave room for the null terminator
printf("%s\n",str);
for( i =0;i<6;i++)
printf("%c",str[i]);
Mike
"kingNewbie" <bkjunstNOSPAM@ups.edu> wrote:
>
>How do you convert a string to an array of chars? Do you have to cast it,
>or is there a function that will do it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|