Std :: is no longer defined in MSVC2012

How is it that std :: is no longer part of the std namespace in Visual Studio 2012? Now I need to enable <functional>

I thought the STL libraries remained unchanged on all tools

+4
source share
2 answers

How is it that std :: is no longer part of the std namespace in Visual Studio 2012?

I would be very surprised if this were so.

Now I need to enable <functional.h>

No, you need to include <functional> , as the heading that defines all the standard function objects, including greater .

I thought the STL libraries remained unchanged on all tools

They should be. But the headers are allowed to include other headers, so sometimes you find that something is available, even if you did not include the correct header. But you cannot rely on it, as you have found here. Always include all the headers you need for the things you use.

+15
source

The following example, taken from here , compiles and runs correctly for me in Visual Studio 2012:

 // greater example #include <iostream> // std::cout #include <functional> // std::greater #include <algorithm> // std::sort int main () { int numbers[]={20,40,50,10,30}; std::sort (numbers, numbers+5, std::greater<int>()); for (int i=0; i<5; i++) std::cout << numbers[i] << ' '; std::cout << '\n'; return 0; } 

Output:

50 40 30 20 10

According to the comments on the question and the example above, you need to include <functional> , not <functional.h> .

+2
source

Source: https://habr.com/ru/post/1480968/


All Articles