Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Ditto on the historical reasons.

The creators of std::string in C++ recognized this shortcoming, so std::string can include the null character. (But be careful constructing a std::string with a null characterconstructing a std::string with a null character!)

If you want to have a C-string (or rather, a quasi-C-string) with a null character, you will have to make to make your own struct.

typedef struct { size_t length; char[] data; //C99 introduced the flexible array member } my_string; 

Or you'll have to keep track of the string length in some other way and pass it to every string function that you write.

Ditto on the historical reasons.

The creators of std::string in C++ recognized this shortcoming, so std::string can include the null character. (But be careful constructing a std::string with a null character!)

If you want to have a C-string (or rather, a quasi-C-string) with a null character, you will have to make to make your own struct.

typedef struct { size_t length; char[] data; //C99 introduced the flexible array member } my_string; 

Or you'll have to keep track of the string length in some other way and pass it to every string function that you write.

Ditto on the historical reasons.

The creators of std::string in C++ recognized this shortcoming, so std::string can include the null character. (But be careful constructing a std::string with a null character!)

If you want to have a C-string (or rather, a quasi-C-string) with a null character, you will have to make to make your own struct.

typedef struct { size_t length; char[] data; //C99 introduced the flexible array member } my_string; 

Or you'll have to keep track of the string length in some other way and pass it to every string function that you write.

Source Link
Paul Draper
  • 84.2k
  • 53
  • 216
  • 303

Ditto on the historical reasons.

The creators of std::string in C++ recognized this shortcoming, so std::string can include the null character. (But be careful constructing a std::string with a null character!)

If you want to have a C-string (or rather, a quasi-C-string) with a null character, you will have to make to make your own struct.

typedef struct { size_t length; char[] data; //C99 introduced the flexible array member } my_string; 

Or you'll have to keep track of the string length in some other way and pass it to every string function that you write.