Is there a way to find this out?
I looked up on google, but the only related thing i found is _setmaxstdio which is a C function. I suppose it also applies in C++?
Also, what does this depend on? On the OS or the compiler?
Printable View
Is there a way to find this out?
I looked up on google, but the only related thing i found is _setmaxstdio which is a C function. I suppose it also applies in C++?
Also, what does this depend on? On the OS or the compiler?
I'd say that this depends on the OS, and any way to manipulate this from your program would also be OS specific.
There's a constant called FOPEN_MAX in limits.h that is a minimum of 20 on most systems, I believe. Of course that's for fopen() and doesn't apply to C++ streams but it might give you some idea at least of the actual number.
Why do you want to know this? What are you trying to do?
There's no standard way to get that information (_setmaxstdio/_getmaxstdio are MS extensions). Anyway, the limit is going to depend on the OS, and as far as standard functions go (ie: fopen, et al), their limits are going to depend on the particular compiler used (although most implementations probably implement the OS default value).
I'm surprised this hasn't been mentioned before:
In Windows, I have no idea how to get the maximum number of files. In Linux you can use getrlimit with the constant RLIMIT_NOFILE. This limit can be configured and can be different on a per program basis. Try running "ulimit -n 1" and then run something like "cat /etc/passwd". Here you set the maximum number of files to 1, which isn't enough and it causes an error. If you have permissions you can call "setrlimit" to change this limit (but there's a hard limit, an actual maximum for this).
All in all, read the setrlimit man pages if you use Linux.
Technically, this limit may not apply to C++ files. But I can't imagine any implementation (especially not of Linux) that does not have one file descriptor per open file.
Keep in mind that stdin, stdout and stderr are file descriptors.