When should you specify std ::?

The following code compiles

#include <cmath>
#include <iostream>

int main()
{
    std::cout << sqrt(4) << std::endl;
}

      

while this is not, because cout is missing std ::

#include <cmath>
#include <iostream>

int main()
{
    cout << sqrt(4) << std::endl;
}

      

why does cout need std and sqrt (even when sqrt is also std :: sqrt)?

+3


source to share





All Articles