> Why didn't the developers who created the standard library develop file IO functions
> that are cross-platform from the beginning?
They (the designers of both C and C++ standard library i/o facilities) did that right from the beginning - by emphasizing the importance of being textual. The primary model for output in C++ is to convert the internal representation of an object into a sequence of human readable characters. Correspondingly, input is the conversion of a sequence of human readable characters into the internal representation of an object.
HTTP, PNG, XML, SOAP, RESTful web services ... all provide evidence of the validity of that design decision.
> What I learn is that if you need to store data in files that will be read and written to on different machines,
> you have to define in the program what endianness should be used.
No. Most often, what you need to do is store the data in (ideally a self-describing) textual format.
ESR on the importance of being textual (emphasis added):
Interoperability, transparency, extensibility, and storage or transaction economy: these are the important themes in designing file formats and application protocols. Interoperability and transparency demand that we focus such designs on clean data representations, rather than putting convenience of implementation or highest possible performance first. Extensibility also favors textual protocols, since binary ones are often harder to extend or subset cleanly. Transaction economy sometimes pushes in the opposite direction — but we shall see that putting that criterion first is a form of premature optimization that it is often wise to resist. ...
...
When you feel the urge to design a complex binary file format, or a complex binary application protocol, it is generally wise to lie down until the feeling passes. ...
...
Designing a textual protocol tends to future-proof your system. ... |
Perhaps you should read the whole chapter
http://www.faqs.org/docs/artu/textualitychapter.html