On Wednesday, 31 July 2013 at 05:56:13 UTC, Ali Çehreli wrote:
On 07/30/2013 02:17 PM, JS wrote:

> A C++ string is null terminated while a D string is not.

I think the OP means std::string, which also is not zero-terminated. (On the other hand, C strings are zero-terminated.)

You can obtain a 0 terminated "const char*" from an std::string in 0(1) using c_str.

While the C++98 standard doesn't mandate it, the above requirement means that 99% of string implementations are using arraysinternally. The C++11 standard *does* mandate that the implementation use arrays internally. So that means you can get a valid char* from &myString[0].

That string will not be 0 terminated, but all the major compiler providers (AFAIK) make that guarantee as an extension.

Reply via email to