I have this structure and I need that in the name field I can enter a data, 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 that in the name field I can enter a data, 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 called c_str()
that returns a pointer of type const char*
to its internal memory.
Copying the string to char*
is something that can be done with the strcpy
function:
std::string cadena = "hola mundo";
char buffer[100];
strcpy(buffer,cadena.c_str());
std::cout << buffer;
By the way, C ++ is not C . The syntax that people in C ++ will expect is this:
struct cliente{
int cedula;
int numCuenta;
char nombre[100];
cliente *izq, *der;
};
Note that I have removed typedef
. This design works in C ++ exactly the same as the code you have put in your example.