I am used to writing codes using stl pair without including any specific header file for using pair. But a friend today told me that I should use utility header whenever I use pair else I will have problem on some compilers. Please tell if this is true. And what is the use of utility header if I can write codes without using it.
Share
You should almost always include header file for every class which you use in your program, otherwise you depend on the fact that some headers internally use a class of your interest, but this can change on another compiler or version. You need to read reference of a class (for example on cppreference.com – http://en.cppreference.com/w/cpp/utility/pair ) and check which header file you need to include – in case of
std::pairyou should add#include <utility>. You cannot depend on the fact, that, for example,iostreamalready includesiomanipand your code compiles when you use manipulators likesetwetc. You cannot – you always should refer to language specs and include required headers.