convert string into character
-
- Posts: 3
- Joined: Fri Sep 23, 2011 12:08 am
convert string into character
how to convert string into character format ?
Re: convert string into character
Hi there,
It would help if you could explain more of what you want to do with the string?
The main reason for doing something like this is sending bytes to a serial port or other device.
An explanation would help us work out what you need.
Cheers.
Dave...
It would help if you could explain more of what you want to do with the string?
The main reason for doing something like this is sending bytes to a serial port or other device.
An explanation would help us work out what you need.
Cheers.
Dave...
Re: convert string into character
Can you be more clear on what you mean by string?
A C++ string class?
A null terminated character array ie
const char * foo="This is a char array";
???
Not really sure what your question is?
A C++ string class?
A null terminated character array ie
const char * foo="This is a char array";
???
Not really sure what your question is?
Re: convert string into character
The only thing that makes sense as a question to me is how to turn a C++ string into a series of c characters, which is what the c_str() function can help with.
Code: Select all
using namespace std;
string a_cpp_string ("some string");
a_c_char_array= new char [a_cpp_str.size()+1];
strcpy (a_c_char_array, a_cpp_string.c_str()); //c_str returns null terminated sequence so strcpy is safe