D
dp1978x
Hi,
is the following legal?
std::string x;
// ...
assert (!x.empty());
x.data()[0] = 'b';
I think not, AFAIK there's no non-const version of "data()", could
someone confirm?
How about this then:
std::string x;
// ...
assert (!x.empty());
const_cast <char *>(x.data())[0] = 'b';
Background: I have a C library that fills array of characters passed
to it by the caller. I need to convert the returned strings to
std::string. I would prefer to do this directly w/o allocating any
temporaries.
Thanks,
D.
is the following legal?
std::string x;
// ...
assert (!x.empty());
x.data()[0] = 'b';
I think not, AFAIK there's no non-const version of "data()", could
someone confirm?
How about this then:
std::string x;
// ...
assert (!x.empty());
const_cast <char *>(x.data())[0] = 'b';
Background: I have a C library that fills array of characters passed
to it by the caller. I need to convert the returned strings to
std::string. I would prefer to do this directly w/o allocating any
temporaries.
Thanks,
D.