user6245072 user6245072 - 1 year ago 95
C++ Question

How can I append part of an array of characters to a string?

Suppose I have a

object and a null-terminated array of characters (or C-style string):

std::string str("This is a ");

const char* cstr = "strings are a really important data type.";

How can I append just the first N characters (in this case, 6, so that
will contain
This is a string
) of a C-style string to a
in the cleanest and most efficient way possible?

Answer Source

How about the append method?

str.append(cstr, 6);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download