I have this structure and I need a data entry in the name field, but I have that data in a string.
typedef struct cliente{
int cedula;
int numCuenta;
char nombre[100];
cliente *izq, *der;
}cliente;
I have this structure and I need a data entry in the name field, but I have that data in a string.
typedef struct cliente{
int cedula;
int numCuenta;
char nombre[100];
cliente *izq, *der;
}cliente;
std::string
has a method calledc_str()
that returns a pointer of typeconst char*
to its internal memory.Copying the string to a
char*
is something that can be done with the functionstrcpy
:By the way, C++ is not C . The syntax people will expect in C++ is this:
Note that I have removed
typedef
. This layout works in C++ exactly the same as the code you've put in your example.according to it says Convert a string to char in c++ I made this small code that served me for this purpose