Warning: geek content ahead.
When my nose is to the grindstone, I use C++ pretty frequently. One (honestly quite minor) thing about the language has been bothering me of late.
The standard library provided with C++ has a set of facilities (“classes” for those of you in the know) for writing things (primarily to files) called iostreams. It also provides a ‘string’ class to manage ‘strings’ of characters; like this sentence, for instance.
To open a file with an iostream (an fstream specifically) you have to provide a filename. Filenames, like all words, consist of a series (or string) of characters. As such, you might hope to provide the requisite file name in a string object…
But your hopes would be dashed. C++ is based on an earlier language, called (get ready for it) C. In C, strings of characters were handled by a special convention: you would “point” to a place in memory that held the series of characters, and a “null” value (zero) would mark the end of the string. In C++ parlance, the creatures that use this convention are called c-strs. Guess what format the fstream class expects of file names? Yup, the c-str.
Now, I don’t mind that fstream accepts c-strs. There are still an awful lot of them floating around, and if you’re mixing C (or C-style) code with C++ — the chances of which are excellent — you’ll appreciate that fstream does this. But why, oh why, does fstream not accept file names in the form of a string object? Why must I convert a C++ construct (the string object containing the file name) to a C construct (a c-str containing the file name) in order to use a C++ construct (the fstream)?
Poor form, in my book.