Hi all,
I need to allocate a buffer large enough to store a copy of a null-terminated
string that is given to me as an argument. The code that I am using looks a lot
like old ugly C code. Is there a "better" C++ way to do this sort of thing (see
below)?
TIA - Bob
---
typedef struct ICInfo_tag {
char* Name;
// Constructor
ICInfo_tag(cons t char* name)
{
// Get a copy of name
size_t nameLen = strlen(name) + 1;
this->Name = static_cast<cha r*>(malloc(name Len));
memcpy(this->Name, name, nameLen);
}
} ICInfo;
I need to allocate a buffer large enough to store a copy of a null-terminated
string that is given to me as an argument. The code that I am using looks a lot
like old ugly C code. Is there a "better" C++ way to do this sort of thing (see
below)?
TIA - Bob
---
typedef struct ICInfo_tag {
char* Name;
// Constructor
ICInfo_tag(cons t char* name)
{
// Get a copy of name
size_t nameLen = strlen(name) + 1;
this->Name = static_cast<cha r*>(malloc(name Len));
memcpy(this->Name, name, nameLen);
}
} ICInfo;
Comment