Benjamin
Benjamin

Reputation: 541

Is the C++ std library platform independent?

I would like to know if some code I write with 'fstream' in C++ will work on all platforms? Is the C++ standard library platform independent or has the headers been rewritten for each platform?

Upvotes: 2

Views: 2181

Answers (6)

And file systems (and their file naming conventions) vary from one system to another. For instance, some (non Unix) file systems are case insensitive, but mot of them are.

And the conventions dictating the file names are widely different.

So while using the standard C++ library will help a lot on portability, there are differences which you should take account of.

Cheers.

Upvotes: 0

Cha Cha
Cha Cha

Reputation: 105

I believe the base behaviour of stl is platform independent. However, the implementation is not platform indifferent. Hence some behaviour will be different.

For example, try to make a string initiates from a null char*, like s = f(), and f() returns a char* null. On Redhat, an exception will be thrown; but on Ubuntu, it will just segfault.

Upvotes: 0

Pubby
Pubby

Reputation: 53037

The standard library is platform independent. How you use it may not be (endianess with files, etc).

The headers are rewritten for each implementation, but they must conform to the standard.

Upvotes: 2

thiton
thiton

Reputation: 36049

Both. You can compile a C++ program using fstream for any platform, but the headers are implementation-dependent. They will differ between compilers and operating systems, but they fulfill the purpose they've been designed and specified for.

Upvotes: 7

Alexander Gessler
Alexander Gessler

Reputation: 46607

<fstream> is part of the Iso C++ standard, so any standard-compliant compiler/toolchain supports it.

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 993055

The C++ standard library is platform independent. You will, of course, need to recompile your program for each platform on which you want it to run.

Between different platforms or different compiler vendors, the actual headers themselves may be different, but they should all provide exactly the same set of services.

Upvotes: 2

Related Questions