0

Consider this code:

#include <iostream>
using namespace std;
int main() {
    //...
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    //...
}

I don't have the limits library included. I can compile this with g++ on my mac without a problem, however on my school computer it gives an error saying '>' is not declared. It will however compile if I include the limits library. Does my mac's g++ automatically include certain libraries? If so, how do I find out what's automatically included?

This is my g++ version:

NoobCoders-MacBook-Pro:as1 NoobCoder$ g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx- 
include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Thanks!

noobcoder
  • 323
  • 1
  • 3
  • 12
  • A header file can `#include` other header files. iostream, for example, sometimes includes string. Other times it forward declares `std::string`. The smart thing to do is always include all of the headers any given file requires so that you do not get nasty surprises when porting or a library update. – user4581301 May 29 '18 at 00:11
  • Here is a related question: [Should I include every header?](https://stackoverflow.com/questions/26611481/should-i-include-every-header) – user4581301 May 29 '18 at 00:13
  • The C++ standard specifies which header libraries must be included in order to use the appropriates templates and classes. Individual C++ implementations are permitted to internally include bits and pieces of various libraries, as part of other libraries, for internal needs. So, on a particular C++ implementation it's possible that including on header file will pull in something from another one. This is not prohibited by the standard but, of course, if you rely on your C++ compiler's behavior it might not work with another C++ compiler. – Sam Varshavchik May 29 '18 at 00:13
  • `limits` is not a library. `limits` is a [header file that is part of the C++ standard library](http://en.cppreference.com/w/cpp/header/limits) – Kevin May 29 '18 at 00:13

0 Answers0