In hindsight, it was an oversight. However, without knowing details about the development history of C++, I’d venture the guess that this oversight has good reasons, rooted in theory. See, a conversion from number to string and vice versa is far from trivial, and it doesn’t fit the normal definition of a “cast” very well (in reality, it requires a parser / formatter), even though most other languages do provide such a cast.
Added to that is the fact that C++’ support for string types is rather … pedestrian. C doesn’t even have a real, dedicated type for it, it uses char
arrays instead. C++ goes slightly further but stops well short of proper built-in string support. This can be seen in many aspects, from the fact that the string literal is still a null-terminated char
array, to the broad consensus that std::string
has a bloated, poorly designed interface. And don’t forget that std::string
doesn’t even represent a string! It represents an array of bytes! This is an important distinction, and the reason for this is simply that std::string
is completely encoding agnostic.
Ah, but C++ actually does support proper encoding, and proper parsing and formatting. It simply doesn’t provide it for strings – it provides it for streams.
And there we have it. C++ has no proper string type. Instead, it has input/output streams.